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 ecdfe1dc911db693ec6673954dd9d4d87a1a3839..2e050fd96deedbf43cdb727b12a4aa809039cbda 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 3250d609d0331298146302c395dc5eab6bf6c66e..93d6acc9e44db4506562ff9586c1918decd56dad 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 de24b6c847b288f279772b1add470ddf9406292c..9090a2d873c1776024e7fdf3c884a9a7a0219886 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 ab12fc1c531c29fd246a7bf44e395a0e8c46e59e..158554bd9a87b4620a0060eb7e15087fde2102a4 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 dab53f1c48e30a620ea8707f52eaa687b63e821b..cf6c1ce9c5aad584b4a1341c2e6c468f5c36cc73 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 56673f6863764599830e04be05a8d4c33e93d93b..cbb83575c022324fde0ec9f3f75884482fb375ae 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 049ced548e2cb54ac8b38af3314fa066e1c74d18..b8ce304c213002b8dad0ab789a5db2cae8b0f257 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 16e279260842d0e648cdd8725e0393cefa5de02c..6df67fb6feb2c602ccc312ea87408959fa240460 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 e623f2456a842080ecd71db34ae24902d236c71f..58f38cdc55de39090a8daa2a0e572c7e33c78bd4 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 33efe37810ba5524e950d4ca01383b5ba3abd7b5..0c91d55e8136fb00ce1247fab6d61c6351e4af82 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 4167ef713e1002e56cdc9010389e8eaab53189e0..ea63b00e2726008fd2831db374e8937a79ca3b18 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 9314735ceda05b61d5c075be19bff9404660502e..49d4a7c5aeceb9b3c1d0e32c99b1c2912513a97b 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 af1f9b743bac364eece9154baf93dc671171c0f8..6122fd1dc732099393d676d9b6a1351c5534abe5 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 9b20dc19ade6541f9e406f4e0104c62b8af37076..0e479072a229f4b152e8a87ba31fe4f33cf42be0 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 33cbca87d73f9196929520af2172afb82ff4e744..ab7f905593969227044ade110a297bede8ffdf55 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 4cae8c5287e20758796d774e4a0cfc8c8eec556e..9fc8bdae1cf3f4d8647a8612b3e794c46ed09f7d 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 2a2cf6973e7da28f415737b99677469531d07783..23fd96ef0ef66de3d262dcdda89b79a957322901 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 cf537e7dc9d33c12b7132052e4dcab95c494e03d..557a43f2f8c38882c02f63f74244826c65e56722 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 4552ebb15ebabc7b7ce5231b5d905dfc073d8d43..eb483937d63c7cf01f6c66c91ed1d23b329ffd37 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 e318e7de1e0aa64215dff6eb4daab6e507863f16..f2d138d95a0e33586e2a5aba302beeff04d25318 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 811eb7b492ba9be7a51e83bd06183b028f22401e..f0d1a851be4d645b7c72d11972a767d2596b2925 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;