summaryrefslogtreecommitdiff
path: root/source3/torture/torture.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2008-11-13 23:50:19 +0100
committerVolker Lendecke <vl@samba.org>2008-11-14 20:07:29 +0100
commitf50ad767505cc8847f5f574767b664b57326e468 (patch)
tree30d89a8a21f270563fd6df55333f358704cc2b1b /source3/torture/torture.c
parent5a210cc552f92459dc05c44a435acbcbbe6db9e7 (diff)
downloadsamba-f50ad767505cc8847f5f574767b664b57326e468.tar.gz
samba-f50ad767505cc8847f5f574767b664b57326e468.tar.bz2
samba-f50ad767505cc8847f5f574767b664b57326e468.zip
Actually finish memcache_add_talloc
This fixes a memleak found by Martin Zielinski <mz@seh.de>. Thanks for looking closely! Volker (cherry picked from commit a31a84a078100819809e6d40dbc3df207a50a0b2)
Diffstat (limited to 'source3/torture/torture.c')
-rw-r--r--source3/torture/torture.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 904fb5c262..762ea214d1 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -5291,6 +5291,11 @@ static bool run_local_memcache(int dummy)
DATA_BLOB d1, d2, d3;
DATA_BLOB v1, v2, v3;
+ TALLOC_CTX *mem_ctx;
+ char *str1, *str2;
+ size_t size1, size2;
+ bool ret = false;
+
cache = memcache_init(NULL, 100);
if (cache == NULL) {
@@ -5342,7 +5347,33 @@ static bool run_local_memcache(int dummy)
}
TALLOC_FREE(cache);
- return true;
+
+ cache = memcache_init(NULL, 0);
+
+ mem_ctx = talloc_init("foo");
+
+ str1 = talloc_strdup(mem_ctx, "string1");
+ str2 = talloc_strdup(mem_ctx, "string2");
+
+ memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
+ data_blob_string_const("torture"), str1);
+ size1 = talloc_total_size(cache);
+
+ memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
+ data_blob_string_const("torture"), str2);
+ size2 = talloc_total_size(cache);
+
+ printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
+
+ if (size2 > size1) {
+ printf("memcache leaks memory!\n");
+ goto fail;
+ }
+
+ ret = true;
+ fail:
+ TALLOC_FREE(cache);
+ return ret;
}
static double create_procs(bool (*fn)(int), bool *result)