[dm-devel] [PATCH 4/5] Match FREE and MALLOC/STRDUP/REALLOC

Martin Wilck mwilck at suse.com
Thu Nov 18 15:35:10 UTC 2021


On Thu, 2021-11-18 at 10:46 +0800, lixiaokeng wrote:
> 
> 
> On 2021/11/18 8:47, Benjamin Marzinski wrote:
> > On Tue, Nov 16, 2021 at 10:00:53PM +0800, lixiaokeng wrote:
> > > In _DEBUG_ mode, MALLOC/STRDUP/REALLOC and FREE will record
> > > the memory usage. Match them.
> > 
> > This looks fine, but personally, I'd rather just have all the DEBUG
> > memory code removed. If people want to check memory usage, there's
> > always valgrind.
> > 
> > -Ben
> > 
> > > 
> 
> If MALLOC/STRDUP/REALLOC and FREE is unnecessary, I'll remove this
> patch
> in this series and make a patch remove them latter. What is Martin's
> opinion?

As you saw, I agree with Ben. If you want to make a major contribution,
prepare a patch that gets rid of all those. :-) 

Just note that MALLOC() is really calloc(). 

The only one that that's useful in non-debug mode is FREE(), because it
sets the pointer to NULL, avoiding double-free. Therefore a patch
replacing FREE() with free() would need to assess where that's
necessary (basically always if the data structure that holds the
pointer lives on after the free() call).

Regards
Martin





More information about the dm-devel mailing list