Skip to content

Commit 9642479

Browse files
pks-tgitster
authored andcommitted
convert: fix leaking config strings
In `read_convert_config()`, we end up reading some string values into variables. We don't free any potentially-existing old values though, which will result in a memory leak in case the same key has been defined multiple times. Fix those leaks. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f08999 commit 9642479

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

convert.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,14 +1050,20 @@ static int read_convert_config(const char *var, const char *value,
10501050
* The command-line will not be interpolated in any way.
10511051
*/
10521052

1053-
if (!strcmp("smudge", key))
1053+
if (!strcmp("smudge", key)) {
1054+
FREE_AND_NULL(drv->smudge);
10541055
return git_config_string(&drv->smudge, var, value);
1056+
}
10551057

1056-
if (!strcmp("clean", key))
1058+
if (!strcmp("clean", key)) {
1059+
FREE_AND_NULL(drv->clean);
10571060
return git_config_string(&drv->clean, var, value);
1061+
}
10581062

1059-
if (!strcmp("process", key))
1063+
if (!strcmp("process", key)) {
1064+
FREE_AND_NULL(drv->process);
10601065
return git_config_string(&drv->process, var, value);
1066+
}
10611067

10621068
if (!strcmp("required", key)) {
10631069
drv->required = git_config_bool(var, value);

t/t0021-conversion.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='blob conversion via gitattributes'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910
. "$TEST_DIRECTORY"/lib-terminal.sh
1011

0 commit comments

Comments
 (0)