Eric Sunshine <[email protected]> wrote:
> On Mon, May 16, 2016 at 11:22 PM, Stefan Beller <[email protected]> wrote:
> > When using automated tools to find memory leaks, it is hard to distinguish
> > between actual leaks and intentional non-cleanups at the end of the program,
> > such that the actual leaks hide in the noise.
>
> Considering the signal-to-noise ratio mentioned above, the goal seems
> reasonable, but why pollute the code with #ifdef's all over the place
> by making the cleanup conditional? If you're going though the effort
> of plugging all these leaks, it probably makes sense to do them
> unconditionally.
I haven't checked for git, but I suspect we get speedups by not
calling free(). I've never needed to profile git, but free() at
exit has been a measurable bottleneck in other projects I've
worked on. Often, free() was more expensive than *alloc().
In any case, I like constant conditionals in C or inline wrappers
macros over CPP #ifdefs littered inside functions:
/* in git-compat-util.h */
#ifdef FREE_ALL_MEMORY
static inline void optional_free(void *ptr) {}
#else
# define FREE_ALL_MEMORY (0)
# define optional_free(ptr) free(ptr)
#endif
/* inside any function: */
if (FREE_ALL_MEMORY)
big_function_which_calls_multiple_frees();
Also Valgrind has suppression files, so code modifications may
not be necessary at all.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html