summaryrefslogtreecommitdiff
path: root/testapp.c
diff options
context:
space:
mode:
authorTrond Norbye <trond.norbye@gmail.com>2010-11-10 06:11:24 -0800
committerTrond Norbye <trond.norbye@gmail.com>2010-11-10 06:22:01 -0800
commit16a809e2a06200a624c8742554b8943de87cc356 (patch)
tree4209f2706a7a8648d71a9122120d061cd6521dae /testapp.c
parentdf15887584f0025e7b188e408dd3c9f638d68518 (diff)
downloadmemcached-16a809e2a06200a624c8742554b8943de87cc356.tar.gz
Issue 161 incorrect allocation in cache_create
Diffstat (limited to 'testapp.c')
-rw-r--r--testapp.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/testapp.c b/testapp.c
index 7023ece..cdccd59 100644
--- a/testapp.c
+++ b/testapp.c
@@ -114,6 +114,39 @@ static enum test_return cache_reuse_test(void)
return TEST_PASS;
}
+
+static enum test_return cache_bulkalloc(size_t datasize)
+{
+ cache_t *cache = cache_create("test", datasize, sizeof(char*),
+ NULL, NULL);
+#define ITERATIONS 1024
+ void *ptr[ITERATIONS];
+
+ for (int ii = 0; ii < ITERATIONS; ++ii) {
+ ptr[ii] = cache_alloc(cache);
+ assert(ptr[ii] != 0);
+ memset(ptr[ii], 0xff, datasize);
+ }
+
+ for (int ii = 0; ii < ITERATIONS; ++ii) {
+ cache_free(cache, ptr[ii]);
+ }
+
+#undef ITERATIONS
+ cache_destroy(cache);
+ return TEST_PASS;
+}
+
+static enum test_return test_issue_161(void)
+{
+ enum test_return ret = cache_bulkalloc(1);
+ if (ret == TEST_PASS) {
+ ret = cache_bulkalloc(512);
+ }
+
+ return ret;
+}
+
static enum test_return cache_redzone_test(void)
{
#ifndef HAVE_UMEM_H
@@ -1786,6 +1819,7 @@ struct testcase testcases[] = {
{ "cache_destructor", cache_destructor_test },
{ "cache_reuse", cache_reuse_test },
{ "cache_redzone", cache_redzone_test },
+ { "issue_161", test_issue_161 },
{ "strtol", test_safe_strtol },
{ "strtoll", test_safe_strtoll },
{ "strtoul", test_safe_strtoul },