Skip to content

Commit 5eeb9aa

Browse files
pks-tttaylorr
authored andcommitted
refs: fix memory leak when parsing hideRefs config
When parsing the hideRefs configuration, we first duplicate the config value so that we can modify it. We then subsequently append it to the `hide_refs` string list, which is initialized with `strdup_strings` enabled. As a consequence we again reallocate the string, but never free the first duplicate and thus have a memory leak. While we never clean up the static `hide_refs` variable anyway, this is no excuse to make the leak worse by leaking every value twice. We are also about to change the way this variable will be handled so that we do indeed start to clean it up. So let's fix the memory leak by using the `string_list_append_nodup()` so that we pass ownership of the allocated string to `hide_refs`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 5af5e54 commit 5eeb9aa

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
14351435
CALLOC_ARRAY(hide_refs, 1);
14361436
hide_refs->strdup_strings = 1;
14371437
}
1438-
string_list_append(hide_refs, ref);
1438+
string_list_append_nodup(hide_refs, ref);
14391439
}
14401440
return 0;
14411441
}

0 commit comments

Comments
 (0)