gencache: don't leak cache_path onto talloc tos
authorDavid Disseldorp <ddiss@samba.org>
Mon, 6 Oct 2014 16:21:13 +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/lib/gencache.c

index 3e67d9ebe75d2b4fb1e202b2f0f8f542597505d8..3192b454b8c7e4c67341dd7bfae535ad5860c7e2 100644 (file)
@@ -65,6 +65,9 @@ static bool gencache_init(void)
        if (cache) return True;
 
        cache_fname = cache_path("gencache.tdb");
+       if (cache_fname == NULL) {
+               return false;
+       }
 
        DEBUG(5, ("Opening cache file at %s\n", cache_fname));
 
@@ -101,6 +104,7 @@ static bool gencache_init(void)
                        DEBUG(5, ("gencache_init: Opening cache file %s read-only.\n", cache_fname));
                }
        }
+       TALLOC_FREE(cache_fname);
 
        if (!cache) {
                DEBUG(5, ("Attempt to open gencache.tdb has failed.\n"));
@@ -108,6 +112,11 @@ static bool gencache_init(void)
        }
 
        cache_fname = lock_path("gencache_notrans.tdb");
+       if (cache_fname == NULL) {
+               tdb_close(cache);
+               cache = NULL;
+               return false;
+       }
 
        DEBUG(5, ("Opening cache file at %s\n", cache_fname));
 
@@ -120,10 +129,12 @@ static bool gencache_init(void)
        if (cache_notrans == NULL) {
                DEBUG(5, ("Opening %s failed: %s\n", cache_fname,
                          strerror(errno)));
+               TALLOC_FREE(cache_fname);
                tdb_close(cache);
                cache = NULL;
                return false;
        }
+       TALLOC_FREE(cache_fname);
 
        return True;
 }