]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: fix leak in git_config_get_expiry_in_days()
authorJeff King <peff@peff.net>
Mon, 17 Aug 2020 21:33:13 +0000 (17:33 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Aug 2020 22:35:47 +0000 (15:35 -0700)
We use git_config_get_string() to retrieve the expiry value in a newly
allocated string. But after parsing it, we never free it, leaking the
memory.

We could fix this with a free() obviously, but there's an even better
solution: we can use the non-allocating "tmp" variant of the function;
we only need it to be valid for the lifetime of our parse function.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c

index d92321a279072f019995ac0818fcdf4c10532127..82c6552d8632125af45ad04955f60dfebfe828f3 100644 (file)
--- a/config.c
+++ b/config.c
@@ -2300,11 +2300,11 @@ int git_config_get_expiry(const char *key, const char **output)
 
 int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamp_t now)
 {
-       char *expiry_string;
+       const char *expiry_string;
        intmax_t days;
        timestamp_t when;
 
-       if (git_config_get_string(key, &expiry_string))
+       if (git_config_get_string_tmp(key, &expiry_string))
                return 1; /* no such thing */
 
        if (git_parse_signed(expiry_string, &days, maximum_signed_value_of_type(int))) {