From: Christof Schmitt Date: Mon, 1 Apr 2019 22:38:59 +0000 (-0700) Subject: memcache: Introduce struct for storing talloc pointer X-Git-Tag: tdb-1.4.1~510 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c44f2f76eefb9156cb1d170c92b4ff07dd6a3d5;p=thirdparty%2Fsamba.git memcache: Introduce struct for storing talloc pointer This allows extending the additional data stored for talloced objects later. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13865 Signed-off-by: Christof Schmitt Reviewed-by: Jeremy Allison --- diff --git a/lib/util/memcache.c b/lib/util/memcache.c index 819ba44b443..d0250c6b3ee 100644 --- a/lib/util/memcache.c +++ b/lib/util/memcache.c @@ -27,6 +27,10 @@ static struct memcache *global_cache; +struct memcache_talloc_value { + void *ptr; +}; + struct memcache_element { struct rb_node rb_node; struct memcache_element *prev, *next; @@ -180,19 +184,19 @@ void *memcache_lookup_talloc(struct memcache *cache, enum memcache_number n, DATA_BLOB key) { DATA_BLOB value; - void *result; + struct memcache_talloc_value mtv; if (!memcache_lookup(cache, n, key, &value)) { return NULL; } - if (value.length != sizeof(result)) { + if (value.length != sizeof(mtv)) { return NULL; } - memcpy(&result, value.data, sizeof(result)); + memcpy(&mtv, value.data, sizeof(mtv)); - return result; + return mtv.ptr; } static void memcache_delete_element(struct memcache *cache, @@ -204,12 +208,12 @@ static void memcache_delete_element(struct memcache *cache, if (memcache_is_talloc(e->n)) { DATA_BLOB cache_key, cache_value; - void *ptr; + struct memcache_talloc_value mtv; memcache_element_parse(e, &cache_key, &cache_value); - SMB_ASSERT(cache_value.length == sizeof(ptr)); - memcpy(&ptr, cache_value.data, sizeof(ptr)); - TALLOC_FREE(ptr); + SMB_ASSERT(cache_value.length == sizeof(mtv)); + memcpy(&mtv, cache_value.data, sizeof(mtv)); + TALLOC_FREE(mtv.ptr); } cache->size -= memcache_element_size(e->keylength, e->valuelength); @@ -275,10 +279,11 @@ void memcache_add(struct memcache *cache, enum memcache_number n, if (value.length <= cache_value.length) { if (memcache_is_talloc(e->n)) { - void *ptr; - SMB_ASSERT(cache_value.length == sizeof(ptr)); - memcpy(&ptr, cache_value.data, sizeof(ptr)); - TALLOC_FREE(ptr); + struct memcache_talloc_value mtv; + + SMB_ASSERT(cache_value.length == sizeof(mtv)); + memcpy(&mtv, cache_value.data, sizeof(mtv)); + TALLOC_FREE(mtv.ptr); } /* * We can reuse the existing record @@ -334,8 +339,8 @@ void memcache_add(struct memcache *cache, enum memcache_number n, void memcache_add_talloc(struct memcache *cache, enum memcache_number n, DATA_BLOB key, void *pptr) { + struct memcache_talloc_value mtv; void **ptr = (void **)pptr; - void *p; if (cache == NULL) { cache = global_cache; @@ -344,8 +349,8 @@ void memcache_add_talloc(struct memcache *cache, enum memcache_number n, return; } - p = talloc_move(cache, ptr); - memcache_add(cache, n, key, data_blob_const(&p, sizeof(p))); + mtv.ptr = talloc_move(cache, ptr); + memcache_add(cache, n, key, data_blob_const(&mtv, sizeof(mtv))); } void memcache_flush(struct memcache *cache, enum memcache_number n)