git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFD PATCH 0/3] Free all the memory!

From
EWEric Wong <e@80x24.org>
Date
May 17, 2016, 12:08 UTC
Message-ID
<20160517120815.GA15546@dcvr.yhbt.net>
In-Reply-To
<CAPig+cT9UKEcNXvsQsFDrQycKwMJR5bCter76UL-zpkncniPBw@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 10 quoted lines
> On Mon, May 16, 2016 at 11:22 PM, Stefan Beller <sbeller@google.com> 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.

Previous: Eric SunshineNext: Stefan Beller
Message 8 of 15 in “Free all the memory!”
  1. 0/3 Free all the memory!Stefan Beller, May 17, 2016
  2. 1/3 mv: free memory at the end if desiredStefan Beller, May 17, 2016
  3. Torsten BögershausenMay 17, 2016
  4. 2/3 pack-redundant: free all memoryStefan Beller, May 17, 2016
  5. Eric SunshineMay 17, 2016
  6. 3/3 rev-parse: free all memoryStefan Beller, May 17, 2016
  7. Eric SunshineMay 17, 2016
  8. Eric WongMay 17, 2016
  9. Stefan BellerMay 17, 2016
  10. Junio C HamanoMay 17, 2016
  11. Stefan BellerMay 17, 2016
  12. Eric WongMay 18, 2016
  13. Ævar Arnfjörð BjarmasonMay 18, 2016
  14. David TurnerMay 17, 2016
  15. Matthieu MoyMay 17, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.