lib: Add "mem_ctx" to gencache_get_data_blob
authorVolker Lendecke <vl@samba.org>
Wed, 4 Sep 2013 06:22:43 +0000 (08:22 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 5 Sep 2013 16:16:22 +0000 (09:16 -0700)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/gencache.c
source3/libsmb/dsgetdcname.c
source3/torture/torture.c
source3/utils/net_cache.c

index 078d0398d59bbe95b211a1b6961f38265806cc89..5985d23b65fab299ef76c0ef034704ad5d9db738 100644 (file)
@@ -112,7 +112,8 @@ bool gencache_parse(const char *keystr,
                    void (*parser)(time_t timeout, DATA_BLOB blob,
                                   void *private_data),
                    void *private_data);
-bool gencache_get_data_blob(const char *keystr, DATA_BLOB *blob,
+bool gencache_get_data_blob(const char *keystr, TALLOC_CTX *mem_ctx,
+                           DATA_BLOB *blob,
                            time_t *timeout, bool *was_expired);
 bool gencache_stabilize(void);
 bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob, time_t timeout);
index 08adf2173a74c2cb65351dbac126b345aa0ab502..7d89c7d05ab56e169ebd0683f3677ecfb90cb163 100644 (file)
@@ -368,7 +368,8 @@ bool gencache_del(const char *keystr)
         * element.
         */
 
-       exists = gencache_get_data_blob(keystr, &value, NULL, &was_expired);
+       exists = gencache_get_data_blob(keystr, NULL, &value, NULL,
+                                       &was_expired);
 
        if (!exists && was_expired) {
                /*
@@ -469,6 +470,7 @@ bool gencache_parse(const char *keystr,
 }
 
 struct gencache_get_data_blob_state {
+       TALLOC_CTX *mem_ctx;
        DATA_BLOB *blob;
        time_t timeout;
        bool result;
@@ -491,7 +493,8 @@ static void gencache_get_data_blob_parser(time_t timeout, DATA_BLOB blob,
                return;
        }
 
-       *state->blob = data_blob(blob.data, blob.length);
+       *state->blob = data_blob_talloc(state->mem_ctx, blob.data,
+                                       blob.length);
        if (state->blob->data == NULL) {
                state->result = false;
                return;
@@ -511,13 +514,15 @@ static void gencache_get_data_blob_parser(time_t timeout, DATA_BLOB blob,
  * @retval False for failure
  **/
 
-bool gencache_get_data_blob(const char *keystr, DATA_BLOB *blob,
+bool gencache_get_data_blob(const char *keystr, TALLOC_CTX *mem_ctx,
+                           DATA_BLOB *blob,
                            time_t *timeout, bool *was_expired)
 {
        struct gencache_get_data_blob_state state;
        bool expired = false;
 
        state.result = false;
+       state.mem_ctx = mem_ctx;
        state.blob = blob;
 
        if (!gencache_parse(keystr, gencache_get_data_blob_parser, &state)) {
@@ -705,7 +710,7 @@ bool gencache_get(const char *keystr, char **value, time_t *ptimeout)
        DATA_BLOB blob;
        bool ret = False;
 
-       ret = gencache_get_data_blob(keystr, &blob, ptimeout, NULL);
+       ret = gencache_get_data_blob(keystr, NULL, &blob, ptimeout, NULL);
        if (!ret) {
                return false;
        }
index 6818b01d1142a63cffea6e02d00b381fe7bfd019..4f2aa632fe90123674f88e258c865bd40ae58326 100644 (file)
@@ -334,12 +334,13 @@ static NTSTATUS dsgetdcname_cache_fetch(TALLOC_CTX *mem_ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (!gencache_get_data_blob(key, &blob, NULL, NULL)) {
+       if (!gencache_get_data_blob(key, NULL, &blob, NULL, NULL)) {
                return NT_STATUS_NOT_FOUND;
        }
 
        info = talloc_zero(mem_ctx, struct netr_DsRGetDCNameInfo);
        if (!info) {
+               data_blob_free(&blob);
                return NT_STATUS_NO_MEMORY;
        }
 
index 2d7e87f3e97a77122e628d7e2a304e22f90190af..15bb8f3d7fe7675d737c144e847a533305b19882 100644 (file)
@@ -8172,7 +8172,7 @@ static bool run_local_gencache(int dummy)
                return False;
        }
 
-       if (!gencache_get_data_blob("foo", &blob, NULL, NULL)) {
+       if (!gencache_get_data_blob("foo", NULL, &blob, NULL, NULL)) {
                d_printf("%s: gencache_get_data_blob() failed\n", __location__);
                return False;
        }
@@ -8196,7 +8196,7 @@ static bool run_local_gencache(int dummy)
                return False;
        }
 
-       if (gencache_get_data_blob("foo", &blob, NULL, NULL)) {
+       if (gencache_get_data_blob("foo", NULL, &blob, NULL, NULL)) {
                d_printf("%s: gencache_get_data_blob() on deleted entry "
                         "succeeded\n", __location__);
                return False;
index afcb7a1874f2ca76ee5d82a71e8b09796f143c60..4de3a6ce777e63d0781e81d779e9215315c44ef4 100644 (file)
@@ -242,7 +242,7 @@ static int net_cache_get(struct net_context *c, int argc, const char **argv)
                return -1;
        }
 
-       if (gencache_get_data_blob(keystr, &value, &timeout, NULL)) {
+       if (gencache_get_data_blob(keystr, NULL, &value, &timeout, NULL)) {
                print_cache_entry(keystr, value, timeout, NULL);
                data_blob_free(&value);
                return 0;