lib: Pass mem_ctx to lock_path()
authorVolker Lendecke <vl@samba.org>
Thu, 16 Aug 2018 08:51:44 +0000 (10:51 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 17 Aug 2018 09:30:10 +0000 (11:30 +0200)
Fix a confusing API: Many places TALLOC_FREE the path where it's not
clear you have to do it.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
21 files changed:
source3/intl/lang_tdb.c
source3/lib/cleanupdb.c
source3/lib/g_lock.c
source3/lib/gencache.c
source3/lib/messages.c
source3/lib/server_mutex.c
source3/lib/util_path.c
source3/lib/util_path.h
source3/libads/kerberos.c
source3/locking/brlock.c
source3/locking/leases_db.c
source3/locking/share_mode_lock.c
source3/nmbd/nmbd_namelistdb.c
source3/printing/printer_list.c
source3/rpc_server/fss/srv_fss_agent.c
source3/smbd/smbXsrv_client.c
source3/smbd/smbXsrv_open.c
source3/smbd/smbXsrv_session.c
source3/smbd/smbXsrv_tcon.c
source3/smbd/smbXsrv_version.c
source3/utils/status.c

index ecdfe1d..2e050fd 100644 (file)
@@ -149,7 +149,7 @@ bool lang_tdb_init(const char *lang)
                goto done;
        }
 
-       lpath = lock_path("lang_");
+       lpath = lock_path(talloc_tos(), "lang_");
        if (lpath == NULL) {
                goto done;
        }
index 3250d60..93d6acc 100644 (file)
@@ -38,7 +38,7 @@ static struct tdb_wrap *cleanup_db(void)
                return db;
        }
 
-       db_path = lock_path("smbd_cleanupd.tdb");
+       db_path = lock_path(talloc_tos(), "smbd_cleanupd.tdb");
        if (db_path == NULL) {
                return NULL;
        }
index de24b6c..9090a2d 100644 (file)
@@ -154,7 +154,7 @@ struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
        }
        result->msg = msg;
 
-       db_path = lock_path("g_lock.tdb");
+       db_path = lock_path(talloc_tos(), "g_lock.tdb");
        if (db_path == NULL) {
                TALLOC_FREE(result);
                return NULL;
index ab12fc1..158554b 100644 (file)
@@ -91,7 +91,7 @@ static bool gencache_init(void)
                return false;
        }
 
-       cache_fname = lock_path("gencache_notrans.tdb");
+       cache_fname = lock_path(talloc_tos(), "gencache_notrans.tdb");
        if (cache_fname == NULL) {
                TALLOC_FREE(cache);
                return false;
index dab53f1..cf6c1ce 100644 (file)
@@ -504,7 +504,7 @@ static NTSTATUS messaging_init_internal(TALLOC_CTX *mem_ctx,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       lck_path = lock_path("msg.lock");
+       lck_path = lock_path(talloc_tos(), "msg.lock");
        if (lck_path == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -664,7 +664,7 @@ NTSTATUS messaging_reinit(struct messaging_context *msg_ctx)
                .pid = getpid(), .vnn = msg_ctx->id.vnn
        };
 
-       lck_path = lock_path("msg.lock");
+       lck_path = lock_path(talloc_tos(), "msg.lock");
        if (lck_path == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
index 56673f6..cbb8357 100644 (file)
@@ -70,7 +70,7 @@ struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
                return NULL;
        }
 
-       fname = lock_path("mutex.tdb");
+       fname = lock_path(talloc_tos(), "mutex.tdb");
        if (fname == NULL) {
                TALLOC_FREE(result);
                return NULL;
index 049ced5..b8ce304 100644 (file)
@@ -65,9 +65,9 @@ static char *xx_path(TALLOC_CTX *mem_ctx,
  * @retval Pointer to a talloc'ed string containing the full path.
  **/
 
-char *lock_path(const char *name)
+char *lock_path(TALLOC_CTX *mem_ctx, const char *name)
 {
-       return xx_path(talloc_tos(), name, lp_lock_directory());
+       return xx_path(mem_ctx, name, lp_lock_directory());
 }
 
 /**
index 16e2792..6df67fb 100644 (file)
 #ifndef __LIB_UTIL_PATH_H__
 #define __LIB_UTIL_PATH_H__
 
-char *lock_path(const char *name);
+#include "replace.h"
+#include <talloc.h>
+
+char *lock_path(TALLOC_CTX *mem_ctx, const char *name);
 char *state_path(const char *name);
 char *cache_path(const char *name);
 char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *abs_path);
index e623f24..58f38cd 100644 (file)
@@ -628,7 +628,7 @@ bool create_local_private_krb5_conf_for_domain(const char *realm,
                return false;
        }
 
-       dname = lock_path("smb_krb5");
+       dname = lock_path(talloc_tos(), "smb_krb5");
        if (!dname) {
                return false;
        }
@@ -639,7 +639,7 @@ bool create_local_private_krb5_conf_for_domain(const char *realm,
                goto done;
        }
 
-       tmpname = lock_path("smb_tmp_krb5.XXXXXX");
+       tmpname = lock_path(talloc_tos(), "smb_tmp_krb5.XXXXXX");
        if (!tmpname) {
                goto done;
        }
index 33efe37..0c91d55 100644 (file)
@@ -362,7 +362,7 @@ void brl_init(bool read_only)
                tdb_flags |= TDB_SEQNUM;
        }
 
-       db_path = lock_path("brlock.tdb");
+       db_path = lock_path(talloc_tos(), "brlock.tdb");
        if (db_path == NULL) {
                DEBUG(0, ("out of memory!\n"));
                return;
index 4167ef7..ea63b00 100644 (file)
@@ -41,7 +41,7 @@ bool leases_db_init(bool read_only)
                return true;
        }
 
-       db_path = lock_path("leases.tdb");
+       db_path = lock_path(talloc_tos(), "leases.tdb");
        if (db_path == NULL) {
                return false;
        }
index 9314735..49d4a7c 100644 (file)
@@ -70,7 +70,7 @@ static bool locking_init_internal(bool read_only)
        if (lock_db)
                return True;
 
-       db_path = lock_path("locking.tdb");
+       db_path = lock_path(talloc_tos(), "locking.tdb");
        if (db_path == NULL) {
                return false;
        }
index af1f9b7..6122fd1 100644 (file)
@@ -647,7 +647,7 @@ void dump_all_namelists(void)
        struct subnet_record *subrec;
        char *dump_path;
 
-       dump_path = lock_path("namelist.debug");
+       dump_path = lock_path(talloc_tos(), "namelist.debug");
        if (dump_path == NULL) {
                DEBUG(0, ("out of memory!\n"));
                return;
index 9b20dc1..0e47907 100644 (file)
@@ -39,7 +39,7 @@ static struct db_context *get_printer_list_db(void)
                return db;
        }
 
-       db_path = lock_path("printer_list.tdb");
+       db_path = lock_path(talloc_tos(), "printer_list.tdb");
        if (db_path == NULL) {
                return NULL;
        }
index 33cbca8..ab7f905 100644 (file)
@@ -394,7 +394,7 @@ NTSTATUS srv_fssa_start(struct messaging_context *msg_ctx)
                return NT_STATUS_NO_MEMORY;
        }
 
-       fss_global.db_path = lock_path(FSS_DB_NAME);
+       fss_global.db_path = lock_path(talloc_tos(), FSS_DB_NAME);
        if (fss_global.db_path == NULL) {
                talloc_free(fss_global.mem_ctx);
                return NT_STATUS_NO_MEMORY;
index 4cae8c5..9fc8bda 100644 (file)
@@ -63,7 +63,7 @@ NTSTATUS smbXsrv_client_global_init(void)
        /*
         * This contains secret information like client keys!
         */
-       global_path = lock_path("smbXsrv_client_global.tdb");
+       global_path = lock_path(talloc_tos(), "smbXsrv_client_global.tdb");
        if (global_path == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
index 2a2cf69..23fd96e 100644 (file)
@@ -57,7 +57,7 @@ NTSTATUS smbXsrv_open_global_init(void)
                return NT_STATUS_OK;
        }
 
-       global_path = lock_path("smbXsrv_open_global.tdb");
+       global_path = lock_path(talloc_tos(), "smbXsrv_open_global.tdb");
        if (global_path == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
index cf537e7..557a43f 100644 (file)
@@ -67,7 +67,7 @@ NTSTATUS smbXsrv_session_global_init(struct messaging_context *msg_ctx)
        /*
         * This contains secret information like session keys!
         */
-       global_path = lock_path("smbXsrv_session_global.tdb");
+       global_path = lock_path(talloc_tos(), "smbXsrv_session_global.tdb");
        if (global_path == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
index 4552ebb..eb48393 100644 (file)
@@ -55,7 +55,7 @@ NTSTATUS smbXsrv_tcon_global_init(void)
                return NT_STATUS_OK;
        }
 
-       global_path = lock_path("smbXsrv_tcon_global.tdb");
+       global_path = lock_path(talloc_tos(), "smbXsrv_tcon_global.tdb");
        if (global_path == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
index e318e7d..f2d138d 100644 (file)
@@ -72,7 +72,7 @@ NTSTATUS smbXsrv_version_global_init(const struct server_id *server_id)
 
        frame = talloc_stackframe();
 
-       global_path = lock_path("smbXsrv_version_global.tdb");
+       global_path = lock_path(talloc_tos(), "smbXsrv_version_global.tdb");
        if (global_path == NULL) {
                TALLOC_FREE(frame);
                return NT_STATUS_NO_MEMORY;
index 811eb7b..f0d1a85 100644 (file)
@@ -685,7 +685,7 @@ int main(int argc, const char *argv[])
                int result;
                struct db_context *db;
 
-               db_path = lock_path("locking.tdb");
+               db_path = lock_path(talloc_tos(), "locking.tdb");
                if (db_path == NULL) {
                        d_printf("Out of memory - exiting\n");
                        ret = -1;