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

MyFirstContribution.txt leaks memory

From
Vinayak Dev <vinayakdev.sci@gmail.com>
Date
Dec 16, 2023, 13:45 UTC
Message-ID
<CADE8NaqwR8JA809k9AN_fm8EEcE5-cXgD0PnXf3hatxcYimU1g@mail.gmail.com>

Hello everyone! I was going through the MyFirstContribution tutorial and implemented its code as an exercise to warm up my git skills. However, when I pushed the code to my fork on GitHub, I noticed that it fails the linux-leaks test. So I fired up the leaks checker that MacOS provides and got a number of leaks in the tutorial code. One was that the strbuf commitline was not released, so I was able to fix that trivially.

However, the stack trace for the second leak shows that the memory leaks when git_config() is called on the wt_status struct, which in turn calls the git_default_config() function. As it must go through my .gitconfig, I noticed that when it checks for "core.editor", it calls git_config_string(), where the string is duplicated into the editor_program variable.

This is precisely where the leak seems to be, as pointed out by the stack of function calls. I thought that maybe freeing dest as in free((void *)*dest) in git_config_string() before calling xstrdup() might free up the leakage (this has been done in a number of places in the code-base).

While this does free up the leakage, I am getting a number of failures in the test suite(some of which are occurring even without the changes), particularly related to setting up bare repositories.

Also, as only the tutorial code's binary(./bin-wrappers/git psuh) that I implemented leaks memory, I suspect that it is my fault somewhere.

Could anyone point out what is the correct way to free up memory in this case? Or would the situation warrant adding the call to free() in git_config_string()?

Thanks a lot! Vinayak

Message 1 of 1 in “MyFirstContribution.txt leaks memory”
  1. Vinayak DevDec 16, 2023

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.