From d3c689fc5c80431b7e72150f72465b3d255a6f02 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 4 Sep 2013 08:57:59 +0200 Subject: lib: Use "mem_ctx" arg in gencache_get Signed-off-by: Volker Lendecke Signed-off-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Thu Sep 5 20:09:21 CEST 2013 on sn-devel-104 --- source3/lib/gencache.c | 24 ++++++++++++++---------- source3/lib/idmap_cache.c | 14 +++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 1ecaad5be5..2c5e9ab424 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -711,7 +711,7 @@ bool gencache_get(const char *keystr, TALLOC_CTX *mem_ctx, char **value, DATA_BLOB blob; bool ret = False; - ret = gencache_get_data_blob(keystr, NULL, &blob, ptimeout, NULL); + ret = gencache_get_data_blob(keystr, mem_ctx, &blob, ptimeout, NULL); if (!ret) { return false; } @@ -725,11 +725,7 @@ bool gencache_get(const char *keystr, TALLOC_CTX *mem_ctx, char **value, return false; } if (value) { - *value = SMB_STRDUP((char *)blob.data); - data_blob_free(&blob); - if (*value == NULL) { - return false; - } + *value = talloc_move(mem_ctx, (char **)&blob.data); return true; } data_blob_free(&blob); @@ -783,8 +779,11 @@ static int gencache_iterate_blobs_fn(struct tdb_context *tdb, TDB_DATA key, keystr = (char *)key.dptr; } else { /* ensure 0-termination */ - keystr = SMB_STRNDUP((char *)key.dptr, key.dsize); + keystr = talloc_strndup(talloc_tos(), (char *)key.dptr, key.dsize); free_key = keystr; + if (keystr == NULL) { + goto done; + } } if (!gencache_pull_timeout((char *)data.dptr, &timeout, &endptr)) { @@ -806,7 +805,7 @@ static int gencache_iterate_blobs_fn(struct tdb_context *tdb, TDB_DATA key, timeout, state->private_data); done: - SAFE_FREE(free_key); + TALLOC_FREE(free_key); return 0; } @@ -862,8 +861,11 @@ static void gencache_iterate_fn(const char *key, DATA_BLOB value, valstr = (char *)value.data; } else { /* ensure 0-termination */ - valstr = SMB_STRNDUP((char *)value.data, value.length); + valstr = talloc_strndup(talloc_tos(), (char *)value.data, value.length); free_val = valstr; + if (valstr == NULL) { + goto done; + } } DEBUG(10, ("Calling function with arguments " @@ -872,7 +874,9 @@ static void gencache_iterate_fn(const char *key, DATA_BLOB value, state->fn(key, valstr, timeout, state->private_data); - SAFE_FREE(free_val); + done: + + TALLOC_FREE(free_val); } void gencache_iterate(void (*fn)(const char *key, const char *value, diff --git a/source3/lib/idmap_cache.c b/source3/lib/idmap_cache.c index 627ced30b3..ffd3c1955c 100644 --- a/source3/lib/idmap_cache.c +++ b/source3/lib/idmap_cache.c @@ -48,7 +48,7 @@ bool idmap_cache_find_sid2unixid(const struct dom_sid *sid, struct unixid *id, if (key == NULL) { return false; } - ret = gencache_get(key, NULL, &value, &timeout); + ret = gencache_get(key, talloc_tos(), &value, &timeout); if (!ret) { goto done; } @@ -128,7 +128,7 @@ bool idmap_cache_find_sid2unixid(const struct dom_sid *sid, struct unixid *id, done: TALLOC_FREE(key); - SAFE_FREE(value); + TALLOC_FREE(value); return ret; } @@ -209,7 +209,7 @@ bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired) if (key == NULL) { return false; } - ret = gencache_get(key, NULL, &value, &timeout); + ret = gencache_get(key, talloc_tos(), &value, &timeout); TALLOC_FREE(key); if (!ret) { return false; @@ -218,7 +218,7 @@ bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired) if (value[0] != '-') { ret = string_to_sid(sid, value); } - SAFE_FREE(value); + TALLOC_FREE(value); if (ret) { *expired = (timeout <= time(NULL)); } @@ -246,7 +246,7 @@ bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired) if (key == NULL) { return false; } - ret = gencache_get(key, NULL, &value, &timeout); + ret = gencache_get(key, talloc_tos(), &value, &timeout); TALLOC_FREE(key); if (!ret) { return false; @@ -255,7 +255,7 @@ bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired) if (value[0] != '-') { ret = string_to_sid(sid, value); } - SAFE_FREE(value); + TALLOC_FREE(value); if (ret) { *expired = (timeout <= time(NULL)); } @@ -431,7 +431,7 @@ static bool idmap_cache_del_xid(char t, int xid) time_t timeout; bool ret = true; - if (!gencache_get(key, NULL, &sid_str, &timeout)) { + if (!gencache_get(key, mem_ctx, &sid_str, &timeout)) { DEBUG(3, ("no entry: %s\n", key)); ret = false; goto done; -- cgit