[前][次][番号順一覧][スレッド一覧]

ruby-changes:48888

From: nobu <ko1@a...>
Date: Mon, 4 Dec 2017 15:08:36 +0900 (JST)
Subject: [ruby-changes:48888] nobu:r61006 (trunk): ifaddr.c: fix memsize

nobu	2017-12-04 15:08:30 +0900 (Mon, 04 Dec 2017)

  New Revision: 61006

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61006

  Log:
    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.

  Modified files:
    trunk/ext/socket/ifaddr.c
Index: ext/socket/ifaddr.c
===================================================================
--- ext/socket/ifaddr.c	(revision 61005)
+++ ext/socket/ifaddr.c	(revision 61006)
@@ -54,11 +54,12 @@ ifaddr_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/socket/ifaddr.c#L54
 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) https://github.com/ruby/ruby/blob/trunk/ext/socket/ifaddr.c#L106
         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;
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]