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 <gitster@pobox.com>

Junio C Hamano committed Feb 2, 2016 at 15:42 UTC 8384c139cb9409fb3cf5ef70afff263917581258
1 file changed +4 -2
git.c
+4 -2
@@ -54,10 +54,12 @@ static void restore_env(int external_alias)
54 if (external_alias &&
55 !strcmp(env_names[i], GIT_PREFIX_ENVIRONMENT))
56 continue;
57 - if (orig_env[i])
57 + if (orig_env[i]) {
58 setenv(env_names[i], orig_env[i], 1);
59 - else
59 + free(orig_env[i]);
60 + } else {
61 unsetenv(env_names[i]);
62 + }
63 }
64 }
65