ruby-changes:31042
From: mame <ko1@a...>
Date: Wed, 2 Oct 2013 21:41:36 +0900 (JST)
Subject: [ruby-changes:31042] mame:r43121 (trunk): * ext/socket/ifaddr.c (rsock_getifaddrs): fix possible memory leak.
mame 2013-10-02 21:41:28 +0900 (Wed, 02 Oct 2013) New Revision: 43121 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43121 Log: * 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. Modified files: trunk/ChangeLog trunk/ext/socket/ifaddr.c Index: ChangeLog =================================================================== --- ChangeLog (revision 43120) +++ ChangeLog (revision 43121) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Oct 2 21:38:30 2013 Yusuke Endoh <mame@t...> + + * 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. + Wed Oct 2 21:37:04 2013 Yusuke Endoh <mame@t...> * random.c (make_seed_value): a local array declaration was accessed Index: ext/socket/ifaddr.c =================================================================== --- ext/socket/ifaddr.c (revision 43120) +++ ext/socket/ifaddr.c (revision 43121) @@ -105,6 +105,10 @@ rsock_getifaddrs(void) https://github.com/ruby/ruby/blob/trunk/ext/socket/ifaddr.c#L105 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++; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/