]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: libsmb: Cleanup - make namecache_key() use talloc.
authorJeremy Allison <jra@samba.org>
Wed, 15 Jul 2020 20:37:59 +0000 (13:37 -0700)
committerVolker Lendecke <vl@samba.org>
Thu, 16 Jul 2020 06:52:36 +0000 (06:52 +0000)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/libsmb/namecache.c

index a4de493b08ea417450bae8c934c5ce0e00cb3a53..5457a9d47cc95a7a1556a6f783c49720c173d96f 100644 (file)
@@ -191,13 +191,14 @@ static int ipstr_list_parse(const char *ipstr_list, struct ip_service **ip_list)
  *         type number
  */
 
-static char *namecache_key(const char *name,
-                               int name_type)
+static char *namecache_key(TALLOC_CTX *ctx,
+                          const char *name,
+                          int name_type)
 {
-       char *keystr = NULL;
-       asprintf_strupper_m(&keystr, NBTKEY_FMT, name, name_type);
-
-       return keystr;
+       return talloc_asprintf_strupper_m(ctx,
+                                         NBTKEY_FMT,
+                                         name,
+                                         name_type);
 }
 
 /**
@@ -246,7 +247,7 @@ bool namecache_store(const char *name,
                DEBUGADD(5, ("\n"));
        }
 
-       key = namecache_key(name, name_type);
+       key = namecache_key(frame, name, name_type);
        if (!key) {
                goto out;
        }
@@ -267,7 +268,7 @@ bool namecache_store(const char *name,
 
   out:
 
-       SAFE_FREE(key);
+       TALLOC_FREE(key);
        SAFE_FREE(value_string);
        TALLOC_FREE(frame);
        return ret;
@@ -308,14 +309,14 @@ bool namecache_fetch(const char *name,
        /*
         * Use gencache interface - lookup the key
         */
-       key = namecache_key(name, name_type);
+       key = namecache_key(talloc_tos(), name, name_type);
        if (!key) {
                return false;
        }
 
        if (!gencache_get(key, talloc_tos(), &value, &timeout)) {
                DEBUG(5, ("no entry for %s#%02X found.\n", name, name_type));
-               SAFE_FREE(key);
+               TALLOC_FREE(key);
                return false;
        }
 
@@ -326,7 +327,7 @@ bool namecache_fetch(const char *name,
         */
        *num_names = ipstr_list_parse(value, ip_list);
 
-       SAFE_FREE(key);
+       TALLOC_FREE(key);
        TALLOC_FREE(value);
 
        return *num_names > 0; /* true only if some ip has been fetched */
@@ -346,12 +347,12 @@ bool namecache_delete(const char *name, int name_type)
                return false; /* Don't fetch non-real name types. */
        }
 
-       key = namecache_key(name, name_type);
+       key = namecache_key(talloc_tos(), name, name_type);
        if (!key) {
                return false;
        }
        ret = gencache_del(key);
-       SAFE_FREE(key);
+       TALLOC_FREE(key);
        return ret;
 }