BCRSMatrix deallocator seems to have a memory leak
When using an address sanitizer (-fsanitize=address
), I get a message on matrix deconstruction saying that objects passed on delete do not match. The important bit is the size of the allocated and deallocated memory:
- size of the allocated type: 19208 bytes;
- size of the deallocated type: 8 bytes.
Checking out the lines where it diagnoses the issue, allocation happens when resting the shaped pointer to the sparsity pattern j_
:
j_.reset(sizeAllocator_.allocate(allocationSize_),Deallocator(sizeAllocator_));
Now, the Deallocator
functor in the line above looks like this:
void operator()(size_type* p) { sizeAllocator_.deallocate(p,1); }
The second argument refers to the size to the deallocation chunk. 1
means that it will only deallocate 1*sizeof(T)
bytes while we actually need allocationSize_*sizeof(T)
bytes which matches with the allocated chunk of memory. So this may explain the warning. When setting the deallocator with allocationSize_
the warning goes away. I could not find the Deallocator
object being used elsewhere, so it seems safe to change its behaviour here. If this makes sense, I can push a MR with the fix.