From: Erik Faye-Lund Date: Mon, 07 Feb 2011 21:12:22 GMT Subject: Re: [PATCH v2] commit: fix memory-leak Message-ID: In-Reply-To: <1297110111-7620-1-git-send-email-kusmabite@gmail.com> On Mon, Feb 7, 2011 at 9:21 PM, Erik Faye-Lund wrote: > The name, email and date strings are some times allocated on the > heap, but not free'd. Fix this by making sure they are allways > heap-allocated, so we can safely free the memory. > > At the same time, this fixes a problem with strict-POSIX getenv > implementations. POSIX says "The return value from getenv() may > point to static data which may be overwritten by subsequent calls > to getenv()", so not duplicating the strings is a potential bug. > > Signed-off-by: Erik Faye-Lund > --- > Fixed typo in commit message, as pointed out by Matthieu Moy. > >  builtin/commit.c  |    9 ++++++--- >  git-compat-util.h |    1 + >  wrapper.c         |    6 ++++++ >  3 files changed, 13 insertions(+), 3 deletions(-) > > diff --git a/builtin/commit.c b/builtin/commit.c > index 03cff5a..e5a649e 100644 > --- a/builtin/commit.c > +++ b/builtin/commit.c > @@ -465,9 +465,9 @@ static void determine_author_info(struct strbuf *author_ident) >  { >        char *name, *email, *date; > > -       name = getenv("GIT_AUTHOR_NAME"); > -       email = getenv("GIT_AUTHOR_EMAIL"); > -       date = getenv("GIT_AUTHOR_DATE"); > +       name = xgetenv("GIT_AUTHOR_NAME"); > +       email = xgetenv("GIT_AUTHOR_EMAIL"); > +       date = xgetenv("GIT_AUTHOR_DATE"); > >        if (use_message && !renew_authorship) { >                const char *a, *lb, *rb, *eol; > @@ -507,6 +507,9 @@ static void determine_author_info(struct strbuf *author_ident) >                date = force_date; >        strbuf_addstr(author_ident, fmt_ident(name, email, date, >                                              IDENT_ERROR_ON_NO_NAME)); > +       free(name); > +       free(email); > +       free(date); Hmm, but I'm getting a crash here on Linux. Guess I need to debug a bit...