samlogon_cache: don't leak cache_path onto talloc tos
authorDavid Disseldorp <ddiss@samba.org>
Mon, 6 Oct 2014 16:21:17 +0000 (18:21 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 6 Oct 2014 17:18:05 +0000 (19:18 +0200)
Also check for allocation failures.

Reported-by: Franz Pförtsch <franz.pfoertsch@brose.com>
Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/libsmb/samlogon_cache.c

index 0a157d48463bad8ee290056f979408c0bec50cb4..1f1ab1d46e8b38bf65f62295a7d0b2f33fde3844 100644 (file)
@@ -38,7 +38,7 @@ static TDB_CONTEXT *netsamlogon_tdb = NULL;
 bool netsamlogon_cache_init(void)
 {
        bool first_try = true;
-       const char *path = NULL;
+       char *path = NULL;
        int ret;
        struct tdb_context *tdb;
 
@@ -47,6 +47,9 @@ bool netsamlogon_cache_init(void)
        }
 
        path = cache_path(NETSAMLOGON_TDB);
+       if (path == NULL) {
+               return false;
+       }
 again:
        tdb = tdb_open_log(path, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
                           O_RDWR | O_CREAT, 0600);
@@ -63,10 +66,12 @@ again:
        }
 
        netsamlogon_tdb = tdb;
+       talloc_free(path);
        return true;
 
 clear:
        if (!first_try) {
+               talloc_free(path);
                return false;
        }
        first_try = false;