summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-04 06:08:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-04 06:08:30 +0000
commit7101611b7608094fc83071a16367c580bc97415e (patch)
tree6e946cd2fbc8f04fa060ac7f061c323afacaad4f
parent8e7560bbaf96d70a91e433b202cf5a74fba084ac (diff)
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
-rw-r--r--ext/socket/ifaddr.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/ext/socket/ifaddr.c b/ext/socket/ifaddr.c
index f4c1698..a2dce23 100644
--- a/ext/socket/ifaddr.c
+++ b/ext/socket/ifaddr.c
@@ -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;