@matheusbsbs / matheus-bagliano / commits / 3a2674337c
Fork 0

compat/setenv: do not free what we fed putenv(3).

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 4, 2005 at 14:41 UTC 3a2674337c12e958f8c697af991a0ef6c06ddd4d
1 file changed +6 -2
compat/setenv.c
+6 -2
@@ -16,7 +16,7 @@ int gitsetenv(const char *name, const char *value, int replace)
16
17 namelen = strlen(name);
18 valuelen = strlen(value);
19 - envstr = malloc((namelen + valuelen + 2) * sizeof(char));
19 + envstr = malloc((namelen + valuelen + 2));
20 if (!envstr) return -1;
21
22 memcpy(envstr, name, namelen);
@@ -25,7 +25,11 @@ int gitsetenv(const char *name, const char *value, int replace)
25 envstr[namelen + valuelen + 1] = 0;
26
27 out = putenv(envstr);
28 + /* putenv(3) makes the argument string part of the environment,
29 + * and changing that string modifies the environment --- which
30 + * means we do not own that storage anymore. Do not free
31 + * envstr.
32 + */
33
29 - free(envstr);
34 return out;
35 }