[memcached] plindner, r466: Merge in two changes from trunk.

commits at code.sixapart.com commits at code.sixapart.com
Tue Mar 6 10:45:29 UTC 2007


Merge in two changes from trunk.

  svn merge -r 463:465 http://code.sixapart.com/svn/memcached/trunk



U   branches/multithreaded/server/ChangeLog
U   branches/multithreaded/server/memcached.c
U   branches/multithreaded/server/slabs.c


Modified: branches/multithreaded/server/ChangeLog
===================================================================
--- branches/multithreaded/server/ChangeLog	2007-03-06 07:28:30 UTC (rev 465)
+++ branches/multithreaded/server/ChangeLog	2007-03-06 10:45:28 UTC (rev 466)
@@ -1,3 +1,10 @@
+2007-03-05  Paul Lindner  <lindner at inuus.com>
+	* Avoid type-punning.  Do a more efficient realloc inside the
+	  conn_shrink routine.
+
+        * Fix overflow bug where uninitialized access to slabclass caused
+	  size-0 mallocs during slab preallocation.
+
 2007-03-05
 	* Steven Grimm <sgrimm at facebook.com>: Per-object-type stats collection
 	  support. Specify the object type delimiter with the -D command line

Modified: branches/multithreaded/server/memcached.c
===================================================================
--- branches/multithreaded/server/memcached.c	2007-03-06 07:28:30 UTC (rev 465)
+++ branches/multithreaded/server/memcached.c	2007-03-06 10:45:28 UTC (rev 466)
@@ -376,18 +376,6 @@
     return;
 }
 
-/*
- * Reallocates memory and updates a buffer size if successful.
- */
-int do_realloc(void **orig, int newsize, int bytes_per_item, int *size) {
-    void *newbuf = realloc(*orig, newsize * bytes_per_item);
-    if (newbuf) {
-        *orig = newbuf;
-        *size = newsize;
-        return 1;
-    }
-    return 0;
-}
 
 /*
  * Shrinks a connection's buffers if they're too big.  This prevents
@@ -397,27 +385,48 @@
  * This should only be called in between requests since it can wipe output
  * buffers!
  */
-void conn_shrink(conn *c) {
+static void conn_shrink(conn *c) {
     if (c->udp)
         return;
 
     if (c->rsize > READ_BUFFER_HIGHWAT && c->rbytes < DATA_BUFFER_SIZE) {
         if (c->rcurr != c->rbuf)
             memmove(c->rbuf, c->rcurr, c->rbytes);
-        do_realloc((void **)&c->rbuf, DATA_BUFFER_SIZE, 1, &c->rsize);
+
+        char *newbuf = (char*) realloc((void*)c->rbuf, DATA_BUFFER_SIZE);
+        if (newbuf) {
+            c->rbuf = newbuf;
+            c->rsize = DATA_BUFFER_SIZE;
+        }
+        /* TODO check other branch... */
         c->rcurr = c->rbuf;
     }
 
     if (c->isize > ITEM_LIST_HIGHWAT) {
-        do_realloc((void **)&c->ilist, ITEM_LIST_INITIAL, sizeof(c->ilist[0]), &c->isize);
+        item **newbuf = (item**) realloc((void*)&c->ilist, ITEM_LIST_INITIAL * sizeof(c->ilist[0]));
+        if (newbuf) {
+            c->ilist = newbuf;
+            c->isize = ITEM_LIST_INITIAL;
+        }
+	/* TODO check error condition? */
     }
 
     if (c->msgsize > MSG_LIST_HIGHWAT) {
-        do_realloc((void **)&c->msglist, MSG_LIST_INITIAL, sizeof(c->msglist[0]), &c->msgsize);
+        struct msghdr *newbuf = (struct msghdr*) realloc((void*)&c->msglist, MSG_LIST_INITIAL * sizeof(c->msglist[0]));
+        if (newbuf) {
+            c->msglist = newbuf;
+            c->msgsize = MSG_LIST_INITIAL;
+        }
+	/* TODO check error condition? */
     }
 
     if (c->iovsize > IOV_LIST_HIGHWAT) {
-        do_realloc((void **)&c->iov, IOV_LIST_INITIAL, sizeof(c->iov[0]), &c->iovsize);
+        struct iovec* newbuf = (struct iovec *) realloc((void*)&c->iov, IOV_LIST_INITIAL * sizeof(c->iov[0]));
+        if (newbuf) {
+            c->iov = newbuf;
+            c->iovsize = IOV_LIST_INITIAL;
+        }
+	/* TODO check return value */
     }
 }
 

Modified: branches/multithreaded/server/slabs.c
===================================================================
--- branches/multithreaded/server/slabs.c	2007-03-06 07:28:30 UTC (rev 465)
+++ branches/multithreaded/server/slabs.c	2007-03-06 10:45:28 UTC (rev 466)
@@ -115,7 +115,7 @@
     {
         char *pre_alloc = getenv("T_MEMD_SLABS_ALLOC");
         if (!pre_alloc || atoi(pre_alloc)) {
-            slabs_preallocate(limit / POWER_BLOCK);
+            slabs_preallocate(power_largest);
         }
     }
 #endif




More information about the memcached-commits mailing list