1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

ifaddr.c: fix memsize

* ext/socket/ifaddr.c (ifaddr_memsize): do not count the whole
  rb_ifaddr_t array for each elements.  the header size is
  included in the first element for the time being.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-12-04 06:08:30 +00:00
parent 8e7560bbaf
commit 7101611b76

View file

@ -54,11 +54,12 @@ ifaddr_free(void *ptr)
static size_t
ifaddr_memsize(const void *ptr)
{
size_t size = offsetof(rb_ifaddr_root_t, ary);
const rb_ifaddr_t *ifaddr;
const rb_ifaddr_root_t *root;
ifaddr = ptr;
root = get_root(ifaddr);
return sizeof(rb_ifaddr_root_t) + (root->numifaddrs - 1) * sizeof(rb_ifaddr_t);
if (ifaddr->ord == 0) size = sizeof(rb_ifaddr_root_t);
size += sizeof(struct ifaddrs);
return size;
}
static const rb_data_type_t ifaddr_type = {
@ -105,7 +106,7 @@ rsock_getifaddrs(void)
numifaddrs++;
addr = TypedData_Wrap_Struct(rb_cSockIfaddr, &ifaddr_type, 0);
root = xmalloc(sizeof(rb_ifaddr_root_t) + (numifaddrs-1) * sizeof(rb_ifaddr_t));
root = xmalloc(offsetof(rb_ifaddr_root_t, ary) + numifaddrs * sizeof(rb_ifaddr_t));
root->refcount = 0;
root->numifaddrs = numifaddrs;