summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-25 13:31:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-25 13:31:34 +0000
commit4198f1473ab7e34780db04155d01f6cc573f07c6 (patch)
treefb56045a0886f2a0f40553b81c96e7379bb02967 /hash.c
parente1884ec8206916ede741d17ecf3a1748b954e274 (diff)
downloadbundler-4198f1473ab7e34780db04155d01f6cc573f07c6.tar.gz
hash.c: fix memory leak
* hash.c (ruby_setenv): fix memory leak on Windows, free environment strings block after check for the size. [ruby-dev:48323] [Bug #9977] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/hash.c b/hash.c
index 3c888349da..d6ac93fbc7 100644
--- a/hash.c
+++ b/hash.c
@@ -2750,9 +2750,12 @@ ruby_setenv(const char *name, const char *value)
int failed = 0;
check_envname(name);
if (value) {
- const char* p = GetEnvironmentStringsA();
+ char* p = GetEnvironmentStringsA();
+ size_t n;
if (!p) goto fail; /* never happen */
- if (strlen(name) + 2 + strlen(value) + getenvsize(p) >= getenvblocksize()) {
+ n = strlen(name) + 2 + strlen(value) + getenvsize(p);
+ FreeEnvironmentStringsA(p);
+ if (n >= getenvblocksize()) {
goto fail; /* 2 for '=' & '\0' */
}
buf = rb_sprintf("%s=%s", name, value);