diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-08-03 16:24:48 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-08-03 16:24:48 +0000 |
commit | d4132b8ae0e79f3fc21bad0fdba1a79fdd6c48b0 (patch) | |
tree | a6d30da2f33b0bc9c5c27adfdb99a031c4800b6a /hash.c | |
parent | 3aefb61f15ca7d09f8465b7cc8036eec81d0830d (diff) |
merge revision(s) r46550: [Backport #9977]
* 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/branches/ruby_2_1@47053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -2751,9 +2751,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); |