{"thread":{"id":"60620","subject":"MyFirstContribution.txt leaks memory","startedAt":"2023-12-16T13:45:33Z","lastAt":"2023-12-16T13:45:33Z","messageCount":1,"participants":["Vinayak Dev"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"485748","messageId":"CADE8NaqwR8JA809k9AN_fm8EEcE5-cXgD0PnXf3hatxcYimU1g@mail.gmail.com","threadId":"60620","inReplyTo":null,"subject":"MyFirstContribution.txt leaks memory","fromName":"Vinayak Dev","fromEmail":"vinayakdev.sci@gmail.com","sentAt":"2023-12-16T13:45:20Z","receivedAt":"2023-12-16T13:45:33Z","isPatch":false,"sender":{"key":"vinayakdev.sci@gmail.com","avatar":"https://avatars.githubusercontent.com/u/104419489?v=4"},"body":"Hello everyone!\nI was going through the MyFirstContribution tutorial and implemented\nits code as an exercise to warm up my git skills.\nHowever, when I pushed the code to my fork on GitHub, I noticed that\nit fails the linux-leaks test.\nSo I fired up the leaks checker that MacOS provides and got a number\nof leaks in the tutorial code.\nOne was that the strbuf commitline was not released, so I was able to\nfix that trivially.\n\nHowever, the stack trace for the second leak shows that the memory\nleaks  when git_config() is called on the wt_status struct, which in turn\ncalls the git_default_config() function. As it must go through my\n.gitconfig, I noticed that when it checks for \"core.editor\", it calls\ngit_config_string(), where the string is duplicated into the\neditor_program variable.\n\nThis is precisely where the leak seems to be, as pointed out by the\nstack of function calls. I thought that maybe freeing dest as in\nfree((void *)*dest) in git_config_string() before calling xstrdup()\nmight free up the leakage (this has been done in a number of places in\nthe code-base).\n\nWhile this does free up the leakage, I am getting a number of failures in\nthe test suite(some of which are occurring even without the changes),\nparticularly related to setting up bare repositories.\n\nAlso, as only the tutorial code's binary(./bin-wrappers/git psuh) that I\nimplemented leaks memory, I suspect that it is my fault somewhere.\n\nCould anyone point out what is the correct way to free up memory in this case?\nOr would the situation warrant adding the call to free() in git_config_string()?\n\nThanks a lot!\nVinayak\n"}]}