Permalink
Browse files

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

  • Loading branch information...
1 parent b53bf8b commit a28080bf26eb7327109f646f40955705732ad540 Toru Maesaka committed with dustin Apr 6, 2009
Showing with 40 additions and 1 deletion.
  1. +1 −1 memcached.c
  2. +39 −0 t/issue_41.t
View
@@ -1339,7 +1339,7 @@ static bool grow_stats_buf(conn *c, size_t needed) {
size_t nsize = size;
bool rv = true;
- while (nsize < needed) {
+ while (nsize < needed + c->stats.offset) {
nsize = nsize << 1;
}
View
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use POSIX qw(ceil);
+use Test::More tests => 691;
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+use MemcachedTest;
+
+my $server = new_memcached();
+my $sock = $server->sock;
+
+my $factor = 2;
+my $val = "x" x $factor;
+my $key = '';
+
+# SET items of diverse size to the daemon so it can attempt
+# to return a large stats output for slabs
+for (my $i=0; $i<69; $i++) {
+ for (my $j=0; $j<10; $j++) {
+ $key = "$i:$j";
+ print $sock "set key$key 0 0 $factor\r\n$val\r\n";
+ is (scalar <$sock>, "STORED\r\n", "stored key$key");
+ }
+ $factor *= 1.2;
+ $factor = ceil($factor);
+ $val = "x" x $factor;
+}
+
+# This request will kill the daemon if it has not allocated
+# enough memory internally.
+my $stats = mem_stats($sock, "slabs");
+
+# Verify whether the daemon is still running or not by asking
+# it for statistics.
+print $sock "version\r\n";
+my $v = scalar <$sock>;
+ok(defined $v && length($v), "memcached didn't respond");

0 comments on commit a28080b

Please sign in to comment.