Re: [PATCH 3/6] notes: don't leak memory in git_config_get_notes_strategy
- From
Jeff King <peff@peff.net>
- Date
- Mar 30, 2016, 01:13 UTC
- Message-ID
- <20160330011334.GC2237@sigill.intra.peff.net>
- In-Reply-To
- <1459298333-21899-4-git-send-email-sbeller@google.com>
On Tue, Mar 29, 2016 at 05:38:50PM -0700, Stefan Beller wrote:
Show 21 quoted lines
> `value` is just a temporary scratchpad, so we need to make sure it doesn't > leak. It is xstrdup'd in `git_config_get_string_const` and > `parse_notes_merge_strategy` just compares the string against predefined > values, so no need to keep it around longer. > > Signed-off-by: Stefan Beller <sbeller@google.com> > --- > builtin/notes.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/builtin/notes.c b/builtin/notes.c > index ed6f222..d6bab17 100644 > --- a/builtin/notes.c > +++ b/builtin/notes.c > @@ -751,6 +751,7 @@ static int git_config_get_notes_strategy(const char *key, > if (parse_notes_merge_strategy(value, strategy)) > git_die_config(key, "unknown notes merge strategy %s", value); > > + free((void*)value); > return 0; > }
I don't think this is wrong, but would it perhaps be simpler to call git_config_get_value() in the first place, which does not make a copy of the string?
-Peff