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

[PATCH] Fix config_file file leak.

From
CWChris Wilson <cwilson@vigilantsw.com>
Date
Jul 14, 2011, 18:19 UTC
Message-ID
<20110714181948.GA23288@localhost>
Hi,

We are using Sentry (a C/C++ static analysis tool) to analyze git on a nightly basis. Sentry found that a file leak was recently introduced in the commit 924aaf3.

I'm hoping the attached patch correctly fixes up this leak.

Thanks, Chris

-- 
Chris Wilson
http://vigilantsw.com/
Vigilant Software, A C/C++ Static Analysis Company

---
 config.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/config.c b/config.c
index 1fc063b..bf61f09 100644
--- a/config.c
+++ b/config.c
@@ -1434,7 +1434,7 @@ int git_config_rename_section(const char *old_name, const char *new
        struct lock_file *lock = xcalloc(sizeof(struct lock_file), 1);
        int out_fd;
        char buf[1024];
-       FILE *config_file;
+       FILE *config_file = 0;

        if (config_exclusive_filename)
                config_filename = xstrdup(config_exclusive_filename);
@@ -1498,12 +1498,13 @@ int git_config_rename_section(const char *old_name, const char *n
                        goto out;
                }
        }
-       fclose(config_file);
  unlock_and_out:
        if (commit_lock_file(lock) < 0)
                ret = error("could not commit config file %s", config_filename);
  out: 
        free(config_filename);
+        if (config_file)
+               fclose(config_file);
        return ret;
 }

-- 
1.7.0.4
Next: Chris Wilson
Message 1 of 4 in “Fix config_file file leak.”
  1. Fix config_file file leak.Chris Wilson, Jul 14, 2011
  2. Chris WilsonJul 14, 2011
  3. Ramsay JonesJul 19, 2011
  4. Chris WilsonJul 20, 2011

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.