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

Re: [PATCH 0/10] towards clean leak-checker output

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Sep 5, 2017, 20:41 UTC
Message-ID
<CAN0heSrz=tVHj13X+yHJpAR=5o7j8EqbBdw8hvrhcnhbA04QAA@mail.gmail.com>
In-Reply-To
<20170905190212.4xx4xukx2bbtudij@sigill.intra.peff.net>
On 5 September 2017 at 21:02, Jeff King <peff@peff.net> wrote:
Show 23 quoted lines
> On Tue, Sep 05, 2017 at 07:50:10PM +0200, Martin Ågren wrote:
>
>> >     That line is the setting of argv0_path, which is a global (and thus
>> >     shouldn't be marked as leaking). Interestingly, it only happens with
>> >     -O2. Compiling with -O0 works fine. I'm not sure if it's a bug or
>> >     what.
>> >
>> >     I did most of my testing with clang-6.0, which gets this case right.
>>
>> Hmmm, I got the same wrong results (IMHO) from Valgrind, which
>> classified this as "definitely lost". Like you I found that -O0 helped.
>> And yes, that was with gcc. Maybe gcc with optimization somehow manages
>> to hide the pointers from these tools. I know too little about the
>> technical details to have any real ideas, though. My searches did not
>> bring up anything useful. (gcc 5.4.0)
>
> Yeah, I think it is just optimizing out the variable entirely. If
> RUNTIME_PREFIX isn't defined (and it's not for non-Windows platforms)
> then we never look at the variable at all, and it's a dead assignment.
> And the compiler can see that easily because it's got static linkage. So
> it drops the variable completely, but it can't drop the call to
> xstrdup() with the information in exec_cmd.c. It has to call the
> function and throw away the result, resulting in the leak.
I see. Yeah, that makes sense.

FWIW, this series (combined with the other series you mentioned) makes t0000 and t0001 pass for me with gcc/clang. There are actually some leaks in t0000, they're just silently being reported to stderr, since the exit statuses from git are hidden by pipes. Maybe you're already aware of it. Depending on your definition of "running clean" it might be out of scope for this series, which is of course still very interesting and enlightening as it stands.

One is in cmd_show (you did mention git show) where we leak data in rev. The other is some use of strdup. I can't immediately figure out how to get a useful stacktrace (you mentioned this as well) and it's past bed-time here. I'll try to play more with this tomorrow.

Note for self: getting rid of all pipes would probably also help flush out a few leaks (or "introduce" them, depending on your viewpoint).

Martin
Previous: Jeff KingNext: Jeff King
Message 26 of 42 in “towards clean leak-checker output”
  1. 0/10 towards clean leak-checker outputJeff King, Sep 5, 2017
  2. 01/10 test-lib: --valgrind should not override --verbose-logJeff King, Sep 5, 2017
  3. 02/10 test-lib: set LSAN_OPTIONS to abort by defaultJeff King, Sep 5, 2017
  4. 03/10 add: free leaked pathspec after add_files_to_cache()Jeff King, Sep 5, 2017
  5. 04/10 update-index: fix cache entry leak in add_one_file()Jeff King, Sep 5, 2017
  6. 05/10 config: plug user_config leakJeff King, Sep 5, 2017
  7. 06/10 reset: make tree counting less confusingJeff King, Sep 5, 2017
  8. 07/10 reset: free allocated tree buffersJeff King, Sep 5, 2017
  9. 08/10 repository: free fields before overwriting themJeff King, Sep 5, 2017
  10. 09/10 set_git_dir: handle feeding gitdir to itselfJeff King, Sep 5, 2017
  11. Brandon WilliamsSep 7, 2017
  12. 10/10 add UNLEAK annotation for reducing leak false positivesJeff King, Sep 5, 2017
  13. Stefan BellerSep 5, 2017
  14. Jeff KingSep 7, 2017
  15. Stefan BellerSep 7, 2017
  16. Kaartic SivaraamSep 12, 2017
  17. Jeff KingSep 12, 2017
  18. Kaartic SivaraamSep 13, 2017
  19. Martin ÅgrenSep 6, 2017
  20. Jeff KingSep 7, 2017
  21. Kaartic SivaraamSep 12, 2017
  22. Jeff KingSep 12, 2017
  23. Kaartic SivaraamSep 13, 2017
  24. Martin ÅgrenSep 5, 2017
  25. Jeff KingSep 5, 2017
  26. Martin ÅgrenSep 5, 2017
  27. Jeff KingSep 6, 2017
  28. Junio C HamanoSep 6, 2017
  29. 0/2 simplifying !RUNTIME_PREFIXJeff King, Sep 6, 2017
  30. 1/2 system_path: move RUNTIME_PREFIX to a sub-functionJeff King, Sep 6, 2017
  31. Johannes SchindelinSep 6, 2017
  32. Jeff KingSep 6, 2017
  33. 2/2 git_extract_argv0_path: do nothing without RUNTIME_PREFIXJeff King, Sep 6, 2017
  34. 10/10 add UNLEAK annotation for reducing leak false positivesJeff King, Sep 8, 2017
  35. Jonathan TanSep 19, 2017
  36. Jeff KingSep 19, 2017
  37. git-compat-util: make UNLEAK less error-proneJonathan Tan, Sep 19, 2017
  38. Jeff KingSep 19, 2017
  39. git-compat-util: make UNLEAK less error-proneJonathan Tan, Sep 19, 2017
  40. Junio C HamanoSep 20, 2017
  41. Jeff KingSep 20, 2017
  42. Junio C HamanoSep 20, 2017

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.