diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-02 12:41:28 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-02 12:41:28 +0000 |
commit | a6ae6a8b17b31d759ae90f5f6b33cfd5640d70f5 (patch) | |
tree | 8a71e20d2fd90bbe5f7209928e8fc0fb720eebb5 /ext/socket | |
parent | e7f484d469a9cb880501f47b0651378dbf4444f0 (diff) | |
download | ruby-a6ae6a8b17b31d759ae90f5f6b33cfd5640d70f5.tar.gz |
* ext/socket/ifaddr.c (rsock_getifaddrs): fix possible memory leak.
When a system had no interface, this function used xmalloc for root
but did not return any reference to it. This patch fixes it by
immediately returning an empty array if no interface is found.
Coverity Scan found this bug.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/ifaddr.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/ext/socket/ifaddr.c b/ext/socket/ifaddr.c index 5783dfc869..16cd47be5a 100644 --- a/ext/socket/ifaddr.c +++ b/ext/socket/ifaddr.c @@ -105,6 +105,10 @@ rsock_getifaddrs(void) if (ret == -1) rb_sys_fail("getifaddrs"); + if (!ifaddrs) { + return rb_ary_new(); + } + numifaddrs = 0; for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) numifaddrs++; |