Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix for incorrect stats buffer reallocation size and a test case for it

  • Loading branch information...
commit a28080bf26eb7327109f646f40955705732ad540 1 parent b53bf8b
authored April 06, 2009 dustin committed April 06, 2009
2  memcached.c
@@ -1339,7 +1339,7 @@ static bool grow_stats_buf(conn *c, size_t needed) {
1339 1339
     size_t nsize = size;
1340 1340
     bool rv = true;
1341 1341
 
1342  
-    while (nsize < needed) {
  1342
+    while (nsize < needed + c->stats.offset) {
1343 1343
         nsize = nsize << 1;
1344 1344
     }
1345 1345
 
39  t/issue_41.t
... ...
@@ -0,0 +1,39 @@
  1
+#!/usr/bin/perl
  2
+
  3
+use strict;
  4
+use warnings;
  5
+use POSIX qw(ceil);
  6
+use Test::More tests => 691;
  7
+use FindBin qw($Bin);
  8
+use lib "$Bin/lib";
  9
+use MemcachedTest;
  10
+
  11
+my $server = new_memcached();
  12
+my $sock = $server->sock;
  13
+
  14
+my $factor = 2;
  15
+my $val = "x" x $factor;
  16
+my $key = '';
  17
+
  18
+# SET items of diverse size to the daemon so it can attempt
  19
+# to return a large stats output for slabs
  20
+for (my $i=0; $i<69; $i++) {
  21
+    for (my $j=0; $j<10; $j++) {
  22
+        $key = "$i:$j";
  23
+        print $sock "set key$key 0 0 $factor\r\n$val\r\n";
  24
+        is (scalar <$sock>, "STORED\r\n", "stored key$key");
  25
+    }
  26
+    $factor *= 1.2;
  27
+    $factor = ceil($factor);
  28
+    $val = "x" x $factor;
  29
+}
  30
+
  31
+# This request will kill the daemon if it has not allocated
  32
+# enough memory internally.
  33
+my $stats = mem_stats($sock, "slabs");
  34
+
  35
+# Verify whether the daemon is still running or not by asking
  36
+# it for statistics.
  37
+print $sock "version\r\n";
  38
+my $v = scalar <$sock>;
  39
+ok(defined $v && length($v), "memcached didn't respond");

0 notes on commit a28080b

Please sign in to comment.
Something went wrong with that request. Please try again.