Skip to content

Commit 8384c13

Browse files
committed
restore_env(): free the saved environment variable once we are done
Just like we free orig_cwd, which is the value of the original working directory saved in save_env_before_alias(), once we are done with it, the contents of orig_env[] array, saved in the save_env_before_alias() function should be freed; otherwise, the second and subsequent calls to save/restore pair will leak the memory allocated in save_env_before_alias(). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 441981b commit 8384c13

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

git.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ static void restore_env(int external_alias)
5454
if (external_alias &&
5555
!strcmp(env_names[i], GIT_PREFIX_ENVIRONMENT))
5656
continue;
57-
if (orig_env[i])
57+
if (orig_env[i]) {
5858
setenv(env_names[i], orig_env[i], 1);
59-
else
59+
free(orig_env[i]);
60+
} else {
6061
unsetenv(env_names[i]);
62+
}
6163
}
6264
}
6365

0 commit comments

Comments
 (0)