Make memcache_add_talloc NULL out the source pointer
authorVolker Lendecke <vl@samba.org>
Fri, 14 Nov 2008 12:42:54 +0000 (13:42 +0100)
committerVolker Lendecke <vl@samba.org>
Fri, 14 Nov 2008 18:55:46 +0000 (19:55 +0100)
This is an orthogonality measure to make clear this pointer now belongs to the
cache.

source/auth/token_util.c
source/lib/memcache.c
source/lib/util_pw.c
source/passdb/pdb_interface.c
source/torture/torture.c

index cd67c2a213d1d25c061bac6fae7c24416da3d9c2..bdf6124e0f291f46df12c7feb6147f01a5c0d1ba 100644 (file)
@@ -77,7 +77,7 @@ bool nt_token_check_domain_rid( NT_USER_TOKEN *token, uint32 rid )
 
 NT_USER_TOKEN *get_root_nt_token( void )
 {
-       struct nt_user_token *token = NULL;
+       struct nt_user_token *token, *for_cache;
        DOM_SID u_sid, g_sid;
        struct passwd *pw;
        void *cache_data;
@@ -107,9 +107,11 @@ NT_USER_TOKEN *get_root_nt_token( void )
 
        token->privileges = se_disk_operators;
 
+       for_cache = token;
+
        memcache_add_talloc(
                NULL, SINGLETON_CACHE_TALLOC,
-               data_blob_string_const("root_nt_token"), token);
+               data_blob_string_const("root_nt_token"), &for_cache);
 
        return token;
 }
index 8ff75c42ca42872b9d9c543d43831017a581af08..4edd9c65e014146a82f7fff0f66e219f4b61b55c 100644 (file)
@@ -348,9 +348,19 @@ 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 *ptr)
+                        DATA_BLOB key, void *pptr)
 {
-       void *p = talloc_move(cache, &ptr);
+       void **ptr = (void **)pptr;
+       void *p;
+
+       if (cache == NULL) {
+               cache = global_cache;
+       }
+       if (cache == NULL) {
+               return;
+       }
+
+       p = talloc_move(cache, ptr);
        memcache_add(cache, n, key, data_blob_const(&p, sizeof(p)));
 }
 
index c0a44c7e009e7640f6d2737ae6d35467cc55d775..b07fab1b5a457a6e4e8cda35278e1d2f35b1fe5b 100644 (file)
@@ -63,7 +63,7 @@ struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
        }
 
        memcache_add_talloc(NULL, GETPWNAM_CACHE, data_blob_string_const(name),
-                           for_cache);
+                           &for_cache);
 
        return tcopy_passwd(mem_ctx, pw);
 }
index dd9fd1b54004cc99fe392b3d35f37dcea10f15d9..b83d6186df6ebb7c99f2ef1d9fd59347713d5949 100644 (file)
@@ -207,28 +207,28 @@ static struct pdb_methods *pdb_get_methods(void)
 bool pdb_getsampwnam(struct samu *sam_acct, const char *username) 
 {
        struct pdb_methods *pdb = pdb_get_methods();
-       struct samu *cache_copy;
+       struct samu *for_cache;
        const struct dom_sid *user_sid;
 
        if (!NT_STATUS_IS_OK(pdb->getsampwnam(pdb, sam_acct, username))) {
                return False;
        }
 
-       cache_copy = samu_new(NULL);
-       if (cache_copy == NULL) {
+       for_cache = samu_new(NULL);
+       if (for_cache == NULL) {
                return False;
        }
 
-       if (!pdb_copy_sam_account(cache_copy, sam_acct)) {
-               TALLOC_FREE(cache_copy);
+       if (!pdb_copy_sam_account(for_cache, sam_acct)) {
+               TALLOC_FREE(for_cache);
                return False;
        }
 
-       user_sid = pdb_get_user_sid(cache_copy);
+       user_sid = pdb_get_user_sid(for_cache);
 
        memcache_add_talloc(NULL, PDB_GETPWSID_CACHE,
                            data_blob_const(user_sid, sizeof(*user_sid)),
-                           cache_copy);
+                           &for_cache);
 
        return True;
 }
index 8419be76a5098e880680e54aeadab9a49f87e4a9..0bacc07fedceee6576a0e203c9e64b0b85eb635c 100644 (file)
@@ -5253,11 +5253,11 @@ static bool run_local_memcache(int dummy)
        str2 = talloc_strdup(mem_ctx, "string2");
 
        memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
-                           data_blob_string_const("torture"), str1);
+                           data_blob_string_const("torture"), &str1);
        size1 = talloc_total_size(cache);
 
        memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
-                           data_blob_string_const("torture"), str2);
+                           data_blob_string_const("torture"), &str2);
        size2 = talloc_total_size(cache);
 
        printf("size1=%d, size2=%d\n", (int)size1, (int)size2);