@matheusbsbs / matheus-bagliano / commits / 1c890016a1
Fork 0

config: fix leak in git_config_get_expiry_in_days()

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>

Jeff King committed Aug 17, 2020 at 17:33 UTC 1c890016a147536e4a6faa5664eedd8765a01b32
1 file changed +2 -2
config.c
+2 -2
@@ -2300,11 +2300,11 @@ int git_config_get_expiry(const char *key, const char **output)
2300
2301 int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamp_t now)
2302 {
2303 - char *expiry_string;
2303 + const char *expiry_string;
2304 intmax_t days;
2305 timestamp_t when;
2306
2307 - if (git_config_get_string(key, &expiry_string))
2307 + if (git_config_get_string_tmp(key, &expiry_string))
2308 return 1; /* no such thing */
2309
2310 if (git_parse_signed(expiry_string, &days, maximum_signed_value_of_type(int))) {