summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4c353e8)
raw | patch | inline | side by side (parent: 4c353e8)
author | Junio C Hamano <junkio@cox.net> | |
Sun, 4 Dec 2005 22:41:35 +0000 (14:41 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 4 Dec 2005 22:41:35 +0000 (14:41 -0800) |
Signed-off-by: Junio C Hamano <junkio@cox.net>
compat/setenv.c | patch | blob | history |
diff --git a/compat/setenv.c b/compat/setenv.c
index 94acd2da9e2e95f9f9a72061d9575de6079dcaec..b7d76785980b81a6f1057d678d34a732f45ca4cd 100644 (file)
--- a/compat/setenv.c
+++ b/compat/setenv.c
namelen = strlen(name);
valuelen = strlen(value);
- envstr = malloc((namelen + valuelen + 2) * sizeof(char));
+ envstr = malloc((namelen + valuelen + 2));
if (!envstr) return -1;
memcpy(envstr, name, namelen);
envstr[namelen + valuelen + 1] = 0;
out = putenv(envstr);
+ /* putenv(3) makes the argument string part of the environment,
+ * and changing that string modifies the environment --- which
+ * means we do not own that storage anymore. Do not free
+ * envstr.
+ */
- free(envstr);
return out;
}