eventlog: don't leak state_path onto talloc tos
authorDavid Disseldorp <ddiss@samba.org>
Sun, 2 Nov 2014 19:21:24 +0000 (20:21 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 3 Nov 2014 22:46:04 +0000 (23:46 +0100)
Also check for allocation failures.

Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/eventlog/eventlog.c

index 4c6767d550d137682684af96034b8c4925096f2f..b63111e8ccc8713ac67bcb875951af9ce51388af 100644 (file)
@@ -73,7 +73,7 @@ char *elog_tdbname(TALLOC_CTX *ctx, const char *name )
        char *file;
        char *tdbname;
 
-       path = talloc_strdup(ctx, state_path("eventlog"));
+       path = state_path("eventlog");
        if (!path) {
                return NULL;
        }
@@ -84,7 +84,7 @@ char *elog_tdbname(TALLOC_CTX *ctx, const char *name )
                return NULL;
        }
 
-       tdbname = talloc_asprintf(path, "%s/%s", state_path("eventlog"), file);
+       tdbname = talloc_asprintf(ctx, "%s/%s", path, file);
        if (!tdbname) {
                talloc_free(path);
                return NULL;
@@ -372,8 +372,12 @@ ELOG_TDB *elog_open_tdb( const char *logname, bool force_clear, bool read_only )
 
        /* make sure that the eventlog dir exists */
 
-       eventlogdir = state_path( "eventlog" );
+       eventlogdir = state_path("eventlog");
+       if (eventlogdir == NULL) {
+               return NULL;
+       }
        ok = directory_create_or_exist(eventlogdir, 0755);
+       TALLOC_FREE(eventlogdir);
        if (!ok) {
                return NULL;
        }