[PATCH] Fix a talloc_tos() leak in pygpo, change xx_path() calls to take mem_ctx

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Aug 17 08:17:44 UTC 2018


Hi!

Review appreciated!

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de

Meet us at Storage Developer Conference (SDC)
Santa Clara, CA USA, September 24th-27th 2018
-------------- next part --------------
From fe2351bffea0bc9501a451d02176141c54b22612 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 17 Aug 2018 10:11:03 +0200
Subject: [PATCH 1/5] pygpo: Fix a talloc_tos() leak in py_gpo_get_unix_path

cache_path() implicitly puts its result on talloc_tos(). As in
py_gpo_get_unix_path the talloc_stackframe() is only created after the
cache_path() call, we leak the result of cache_path() on
talloc_tos() (which might or might not exist).

This converts the function to the pattern used elsewhere: Create the
stackframe as the very first action and remove it as the very last
action in the function.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 libgpo/pygpo.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c
index 60220a6bc2a..88486424917 100644
--- a/libgpo/pygpo.c
+++ b/libgpo/pygpo.c
@@ -81,6 +81,8 @@ static PyObject *py_gpo_get_unix_path(PyObject *self, PyObject *args,
 	struct GROUP_POLICY_OBJECT *gpo_ptr \
 		= (struct GROUP_POLICY_OBJECT *)pytalloc_get_ptr(self);
 
+	frame = talloc_stackframe();
+
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|s",
 					 discard_const_p(char *, kwlist),
 					 &cache_dir)) {
@@ -99,12 +101,8 @@ static PyObject *py_gpo_get_unix_path(PyObject *self, PyObject *args,
 		}
 	}
 
-	frame = talloc_stackframe();
-
 	status = gpo_get_unix_path(frame, cache_dir, gpo_ptr, &unix_path);
 
-	TALLOC_FREE(frame);
-
 	if (!NT_STATUS_IS_OK(status)) {
 		PyErr_SetString(PyExc_SystemError,
 				"Failed to determine gpo unix path");
@@ -114,6 +112,7 @@ static PyObject *py_gpo_get_unix_path(PyObject *self, PyObject *args,
 	ret = PyStr_FromString(unix_path);
 
 out:
+	TALLOC_FREE(frame);
 	return ret;
 }
 
-- 
2.11.0


From e88fddbe19ddea4cd13d8397dc6a06b6f7b23e15 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 16 Aug 2018 10:45:23 +0200
Subject: [PATCH 2/5] lib: Pass "mem_ctx" down to xx_path

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/util_path.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/source3/lib/util_path.c b/source3/lib/util_path.c
index 5b133dfdc78..049ced548e2 100644
--- a/source3/lib/util_path.c
+++ b/source3/lib/util_path.c
@@ -38,11 +38,13 @@ struct share_params;
  * @retval Pointer to a string containing the full path.
  **/
 
-static char *xx_path(const char *name, const char *rootpath)
+static char *xx_path(TALLOC_CTX *mem_ctx,
+		     const char *name,
+		     const char *rootpath)
 {
 	char *fname = NULL;
 
-	fname = talloc_strdup(talloc_tos(), rootpath);
+	fname = talloc_strdup(mem_ctx, rootpath);
 	if (!fname) {
 		return NULL;
 	}
@@ -65,7 +67,7 @@ static char *xx_path(const char *name, const char *rootpath)
 
 char *lock_path(const char *name)
 {
-	return xx_path(name, lp_lock_directory());
+	return xx_path(talloc_tos(), name, lp_lock_directory());
 }
 
 /**
@@ -78,7 +80,7 @@ char *lock_path(const char *name)
 
 char *state_path(const char *name)
 {
-	return xx_path(name, lp_state_directory());
+	return xx_path(talloc_tos(), name, lp_state_directory());
 }
 
 /**
@@ -91,7 +93,7 @@ char *state_path(const char *name)
 
 char *cache_path(const char *name)
 {
-	return xx_path(name, lp_cache_directory());
+	return xx_path(talloc_tos(), name, lp_cache_directory());
 }
 
 /**
-- 
2.11.0


From 7192060051d6ff2e35909154a64a05a56334ff17 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 16 Aug 2018 10:51:44 +0200
Subject: [PATCH 3/5] lib: Pass mem_ctx to lock_path()

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 at samba.org>
---
 source3/intl/lang_tdb.c                | 2 +-
 source3/lib/cleanupdb.c                | 2 +-
 source3/lib/g_lock.c                   | 2 +-
 source3/lib/gencache.c                 | 2 +-
 source3/lib/messages.c                 | 4 ++--
 source3/lib/server_mutex.c             | 2 +-
 source3/lib/util_path.c                | 4 ++--
 source3/lib/util_path.h                | 5 ++++-
 source3/libads/kerberos.c              | 4 ++--
 source3/locking/brlock.c               | 2 +-
 source3/locking/leases_db.c            | 2 +-
 source3/locking/share_mode_lock.c      | 2 +-
 source3/nmbd/nmbd_namelistdb.c         | 2 +-
 source3/printing/printer_list.c        | 2 +-
 source3/rpc_server/fss/srv_fss_agent.c | 2 +-
 source3/smbd/smbXsrv_client.c          | 2 +-
 source3/smbd/smbXsrv_open.c            | 2 +-
 source3/smbd/smbXsrv_session.c         | 2 +-
 source3/smbd/smbXsrv_tcon.c            | 2 +-
 source3/smbd/smbXsrv_version.c         | 2 +-
 source3/utils/status.c                 | 2 +-
 21 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/source3/intl/lang_tdb.c b/source3/intl/lang_tdb.c
index ecdfe1dc911..2e050fd96de 100644
--- a/source3/intl/lang_tdb.c
+++ b/source3/intl/lang_tdb.c
@@ -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;
 	}
diff --git a/source3/lib/cleanupdb.c b/source3/lib/cleanupdb.c
index 3250d609d03..93d6acc9e44 100644
--- a/source3/lib/cleanupdb.c
+++ b/source3/lib/cleanupdb.c
@@ -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;
 	}
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index de24b6c847b..9090a2d873c 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -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;
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index ab12fc1c531..158554bd9a8 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -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;
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index dab53f1c48e..cf6c1ce9c5a 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -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;
 	}
diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c
index 56673f68637..cbb83575c02 100644
--- a/source3/lib/server_mutex.c
+++ b/source3/lib/server_mutex.c
@@ -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;
diff --git a/source3/lib/util_path.c b/source3/lib/util_path.c
index 049ced548e2..b8ce304c213 100644
--- a/source3/lib/util_path.c
+++ b/source3/lib/util_path.c
@@ -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());
 }
 
 /**
diff --git a/source3/lib/util_path.h b/source3/lib/util_path.h
index 16e27926084..6df67fb6feb 100644
--- a/source3/lib/util_path.h
+++ b/source3/lib/util_path.h
@@ -24,7 +24,10 @@
 #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);
diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c
index e623f2456a8..58f38cdc55d 100644
--- a/source3/libads/kerberos.c
+++ b/source3/libads/kerberos.c
@@ -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;
 	}
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index 33efe37810b..0c91d55e813 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -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;
diff --git a/source3/locking/leases_db.c b/source3/locking/leases_db.c
index 4167ef713e1..ea63b00e272 100644
--- a/source3/locking/leases_db.c
+++ b/source3/locking/leases_db.c
@@ -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;
 	}
diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
index 9314735ceda..49d4a7c5aec 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -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;
 	}
diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c
index af1f9b743ba..6122fd1dc73 100644
--- a/source3/nmbd/nmbd_namelistdb.c
+++ b/source3/nmbd/nmbd_namelistdb.c
@@ -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;
diff --git a/source3/printing/printer_list.c b/source3/printing/printer_list.c
index 9b20dc19ade..0e479072a22 100644
--- a/source3/printing/printer_list.c
+++ b/source3/printing/printer_list.c
@@ -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;
 	}
diff --git a/source3/rpc_server/fss/srv_fss_agent.c b/source3/rpc_server/fss/srv_fss_agent.c
index 33cbca87d73..ab7f9055939 100644
--- a/source3/rpc_server/fss/srv_fss_agent.c
+++ b/source3/rpc_server/fss/srv_fss_agent.c
@@ -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;
diff --git a/source3/smbd/smbXsrv_client.c b/source3/smbd/smbXsrv_client.c
index 4cae8c5287e..9fc8bdae1cf 100644
--- a/source3/smbd/smbXsrv_client.c
+++ b/source3/smbd/smbXsrv_client.c
@@ -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;
 	}
diff --git a/source3/smbd/smbXsrv_open.c b/source3/smbd/smbXsrv_open.c
index 2a2cf6973e7..23fd96ef0ef 100644
--- a/source3/smbd/smbXsrv_open.c
+++ b/source3/smbd/smbXsrv_open.c
@@ -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;
 	}
diff --git a/source3/smbd/smbXsrv_session.c b/source3/smbd/smbXsrv_session.c
index cf537e7dc9d..557a43f2f8c 100644
--- a/source3/smbd/smbXsrv_session.c
+++ b/source3/smbd/smbXsrv_session.c
@@ -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;
 	}
diff --git a/source3/smbd/smbXsrv_tcon.c b/source3/smbd/smbXsrv_tcon.c
index 4552ebb15eb..eb483937d63 100644
--- a/source3/smbd/smbXsrv_tcon.c
+++ b/source3/smbd/smbXsrv_tcon.c
@@ -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;
 	}
diff --git a/source3/smbd/smbXsrv_version.c b/source3/smbd/smbXsrv_version.c
index e318e7de1e0..f2d138d95a0 100644
--- a/source3/smbd/smbXsrv_version.c
+++ b/source3/smbd/smbXsrv_version.c
@@ -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;
diff --git a/source3/utils/status.c b/source3/utils/status.c
index 811eb7b492b..f0d1a851be4 100644
--- a/source3/utils/status.c
+++ b/source3/utils/status.c
@@ -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;
-- 
2.11.0


From 33e1aa9287f428854fd0fa813ea7892bffdf9d3a Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 16 Aug 2018 10:51:44 +0200
Subject: [PATCH 4/5] lib: Pass mem_ctx to state_path()

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 at samba.org>
---
 source3/groupdb/mapping_tdb.c                   | 6 +++---
 source3/lib/eventlog/eventlog.c                 | 4 ++--
 source3/lib/sharesec.c                          | 2 +-
 source3/lib/util_path.c                         | 4 ++--
 source3/lib/util_path.h                         | 2 +-
 source3/modules/vfs_acl_tdb.c                   | 2 +-
 source3/modules/vfs_xattr_tdb.c                 | 2 +-
 source3/nmbd/nmbd_winsserver.c                  | 6 +++---
 source3/passdb/account_pol.c                    | 2 +-
 source3/passdb/pdb_tdb.c                        | 2 +-
 source3/printing/nt_printing.c                  | 6 +++---
 source3/printing/nt_printing_migrate_internal.c | 6 +++---
 source3/printing/nt_printing_tdb.c              | 6 +++---
 source3/registry/reg_backend_db.c               | 4 ++--
 source3/registry/reg_perfcount.c                | 4 ++--
 source3/utils/net_idmap.c                       | 4 ++--
 source3/utils/net_registry.c                    | 2 +-
 source3/utils/smbcontrol.c                      | 4 ++--
 source3/winbindd/idmap_autorid.c                | 2 +-
 source3/winbindd/idmap_tdb.c                    | 2 +-
 source3/winbindd/winbindd.c                     | 2 +-
 source3/winbindd/winbindd_cache.c               | 2 +-
 22 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/source3/groupdb/mapping_tdb.c b/source3/groupdb/mapping_tdb.c
index adc7d0b9d47..3561057214c 100644
--- a/source3/groupdb/mapping_tdb.c
+++ b/source3/groupdb/mapping_tdb.c
@@ -53,7 +53,7 @@ static bool init_group_mapping(void)
 		return true;
 	}
 
-	tdb_path = state_path("group_mapping.tdb");
+	tdb_path = state_path(talloc_tos(), "group_mapping.tdb");
 	if (tdb_path == NULL) {
 		return false;
 	}
@@ -67,7 +67,7 @@ static bool init_group_mapping(void)
 		return false;
 	}
 
-	ldb_path = state_path("group_mapping.ldb");
+	ldb_path = state_path(talloc_tos(), "group_mapping.ldb");
 	if (ldb_path == NULL) {
 		talloc_free(tdb_path);
 		return false;
@@ -1084,7 +1084,7 @@ static bool mapping_switch(const char *ldb_path)
 	}
 
 	/* now rename the old db out of the way */
-	new_path = state_path("group_mapping.ldb.replaced");
+	new_path = state_path(talloc_tos(), "group_mapping.ldb.replaced");
 	if (!new_path) {
 		goto failed;
 	}
diff --git a/source3/lib/eventlog/eventlog.c b/source3/lib/eventlog/eventlog.c
index 9053fdd9a24..4b631180816 100644
--- a/source3/lib/eventlog/eventlog.c
+++ b/source3/lib/eventlog/eventlog.c
@@ -73,7 +73,7 @@ char *elog_tdbname(TALLOC_CTX *ctx, const char *name )
 	char *file;
 	char *tdbname;
 
-	path = state_path("eventlog");
+	path = state_path(talloc_tos(), "eventlog");
 	if (!path) {
 		return NULL;
 	}
@@ -373,7 +373,7 @@ 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(talloc_tos(), "eventlog");
 	if (eventlogdir == NULL) {
 		return NULL;
 	}
diff --git a/source3/lib/sharesec.c b/source3/lib/sharesec.c
index d790b083218..58a2dee3bcf 100644
--- a/source3/lib/sharesec.c
+++ b/source3/lib/sharesec.c
@@ -148,7 +148,7 @@ bool share_info_db_init(void)
 		return True;
 	}
 
-	db_path = state_path("share_info.tdb");
+	db_path = state_path(talloc_tos(), "share_info.tdb");
 	if (db_path == NULL) {
 		return false;
 	}
diff --git a/source3/lib/util_path.c b/source3/lib/util_path.c
index b8ce304c213..efe3e608d7d 100644
--- a/source3/lib/util_path.c
+++ b/source3/lib/util_path.c
@@ -78,9 +78,9 @@ char *lock_path(TALLOC_CTX *mem_ctx, const char *name)
  * @retval Pointer to a talloc'ed string containing the full path.
  **/
 
-char *state_path(const char *name)
+char *state_path(TALLOC_CTX *mem_ctx, const char *name)
 {
-	return xx_path(talloc_tos(), name, lp_state_directory());
+	return xx_path(mem_ctx, name, lp_state_directory());
 }
 
 /**
diff --git a/source3/lib/util_path.h b/source3/lib/util_path.h
index 6df67fb6feb..b189b3e33cb 100644
--- a/source3/lib/util_path.h
+++ b/source3/lib/util_path.h
@@ -28,7 +28,7 @@
 #include <talloc.h>
 
 char *lock_path(TALLOC_CTX *mem_ctx, const char *name);
-char *state_path(const char *name);
+char *state_path(TALLOC_CTX *mem_ctx, const char *name);
 char *cache_path(const char *name);
 char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *abs_path);
 
diff --git a/source3/modules/vfs_acl_tdb.c b/source3/modules/vfs_acl_tdb.c
index bb69170c910..7506e4e34fa 100644
--- a/source3/modules/vfs_acl_tdb.c
+++ b/source3/modules/vfs_acl_tdb.c
@@ -50,7 +50,7 @@ static bool acl_tdb_init(void)
 		return true;
 	}
 
-	dbname = state_path("file_ntacls.tdb");
+	dbname = state_path(talloc_tos(), "file_ntacls.tdb");
 
 	if (dbname == NULL) {
 		errno = ENOSYS;
diff --git a/source3/modules/vfs_xattr_tdb.c b/source3/modules/vfs_xattr_tdb.c
index f67a86f8027..32968ae083f 100644
--- a/source3/modules/vfs_xattr_tdb.c
+++ b/source3/modules/vfs_xattr_tdb.c
@@ -458,7 +458,7 @@ static bool xattr_tdb_init(int snum, TALLOC_CTX *mem_ctx, struct db_context **p_
 	const char *dbname;
 	char *def_dbname;
 
-	def_dbname = state_path("xattr.tdb");
+	def_dbname = state_path(talloc_tos(), "xattr.tdb");
 	if (def_dbname == NULL) {
 		errno = ENOSYS;
 		return false;
diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c
index cd7d3b7fc75..c34bfaea3be 100644
--- a/source3/nmbd/nmbd_winsserver.c
+++ b/source3/nmbd/nmbd_winsserver.c
@@ -601,7 +601,7 @@ bool initialise_wins(void)
 		return True;
 	}
 
-	db_path = state_path("wins.tdb");
+	db_path = state_path(talloc_tos(), "wins.tdb");
 	if (db_path == NULL) {
 		return false;
 	}
@@ -620,7 +620,7 @@ bool initialise_wins(void)
 
 	add_samba_names_to_subnet(wins_server_subnet);
 
-	list_path = state_path(WINS_LIST);
+	list_path = state_path(talloc_tos(), WINS_LIST);
 	if (list_path == NULL) {
 		tdb_close(wins_tdb);
 		return false;
@@ -2493,7 +2493,7 @@ void wins_write_database(time_t t, bool background)
 		}
 	}
 
-	if (!(fname = state_path(WINS_LIST))) {
+	if (!(fname = state_path(talloc_tos(), WINS_LIST))) {
 		goto err_exit;
 	}
 	/* This is safe as the 0 length means "don't expand". */
diff --git a/source3/passdb/account_pol.c b/source3/passdb/account_pol.c
index 421a054f83b..4d94dfe817c 100644
--- a/source3/passdb/account_pol.c
+++ b/source3/passdb/account_pol.c
@@ -220,7 +220,7 @@ bool init_account_policy(void)
 		return True;
 	}
 
-	db_path = state_path("account_policy.tdb");
+	db_path = state_path(talloc_tos(), "account_policy.tdb");
 	if (db_path == NULL) {
 		return false;
 	}
diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c
index 6f3dda6e229..91735ff7084 100644
--- a/source3/passdb/pdb_tdb.c
+++ b/source3/passdb/pdb_tdb.c
@@ -336,7 +336,7 @@ static bool tdbsam_upgrade_next_rid(struct db_context *db)
 		return true;
 	}
 
-	db_path = state_path("winbindd_idmap.tdb");
+	db_path = state_path(talloc_tos(), "winbindd_idmap.tdb");
 	if (db_path == NULL) {
 		return false;
 	}
diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index 633e350ff35..9c4c488040f 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -152,7 +152,7 @@ static bool print_driver_directories_init(void)
 		}
 	}
 
-	driver_path = state_path("DriverStore");
+	driver_path = state_path(talloc_tos(), "DriverStore");
 	if (driver_path == NULL) {
 		talloc_free(mem_ctx);
 		return false;
@@ -165,7 +165,7 @@ static bool print_driver_directories_init(void)
 		return false;
 	}
 
-	driver_path = state_path("DriverStore/FileRepository");
+	driver_path = state_path(talloc_tos(), "DriverStore/FileRepository");
 	if (driver_path == NULL) {
 		talloc_free(mem_ctx);
 		return false;
@@ -178,7 +178,7 @@ static bool print_driver_directories_init(void)
 		return false;
 	}
 
-	driver_path = state_path("DriverStore/Temp");
+	driver_path = state_path(talloc_tos(), "DriverStore/Temp");
 	if (driver_path == NULL) {
 		talloc_free(mem_ctx);
 		return false;
diff --git a/source3/printing/nt_printing_migrate_internal.c b/source3/printing/nt_printing_migrate_internal.c
index dd78e69989e..8bcc2d45a11 100644
--- a/source3/printing/nt_printing_migrate_internal.c
+++ b/source3/printing/nt_printing_migrate_internal.c
@@ -198,9 +198,9 @@ bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx)
 	NTSTATUS status;
 
 	/* paths talloced on new stackframe */
-	drivers_path = state_path("ntdrivers.tdb");
-	printers_path = state_path("ntprinters.tdb");
-	forms_path = state_path("ntforms.tdb");
+	drivers_path = state_path(talloc_tos(), "ntdrivers.tdb");
+	printers_path = state_path(talloc_tos(), "ntprinters.tdb");
+	forms_path = state_path(talloc_tos(), "ntforms.tdb");
 	if ((drivers_path == NULL) || (printers_path == NULL)
 						|| (forms_path == NULL)) {
 		talloc_free(tmp_ctx);
diff --git a/source3/printing/nt_printing_tdb.c b/source3/printing/nt_printing_tdb.c
index ea1e87e4a12..0193b177aec 100644
--- a/source3/printing/nt_printing_tdb.c
+++ b/source3/printing/nt_printing_tdb.c
@@ -349,17 +349,17 @@ bool nt_printing_tdb_upgrade(void)
 	int32_t vers_id;
 	bool ret;
 
-	drivers_path = state_path("ntdrivers.tdb");
+	drivers_path = state_path(talloc_tos(), "ntdrivers.tdb");
 	if (drivers_path == NULL) {
 		ret = false;
 		goto err_out;
 	}
-	printers_path = state_path("ntprinters.tdb");
+	printers_path = state_path(talloc_tos(), "ntprinters.tdb");
 	if (printers_path == NULL) {
 		ret = false;
 		goto err_drvdb_free;
 	}
-	forms_path = state_path("ntforms.tdb");
+	forms_path = state_path(talloc_tos(), "ntforms.tdb");
 	if (forms_path == NULL) {
 		ret = false;
 		goto err_prdb_free;
diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c
index 928572e8a5a..aa97d60abec 100644
--- a/source3/registry/reg_backend_db.c
+++ b/source3/registry/reg_backend_db.c
@@ -733,7 +733,7 @@ WERROR regdb_init(void)
 		return WERR_OK;
 	}
 
-	db_path = state_path("registry.tdb");
+	db_path = state_path(talloc_tos(), "registry.tdb");
 	if (db_path == NULL) {
 		return WERR_NOT_ENOUGH_MEMORY;
 	}
@@ -861,7 +861,7 @@ WERROR regdb_open( void )
 		return WERR_OK;
 	}
 
-	db_path = state_path("registry.tdb");
+	db_path = state_path(talloc_tos(), "registry.tdb");
 	if (db_path == NULL) {
 		return WERR_NOT_ENOUGH_MEMORY;
 	}
diff --git a/source3/registry/reg_perfcount.c b/source3/registry/reg_perfcount.c
index e31f8991642..6fa96f314fb 100644
--- a/source3/registry/reg_perfcount.c
+++ b/source3/registry/reg_perfcount.c
@@ -48,7 +48,7 @@ static char *counters_directory(const char *dbname)
 	char *db_subpath = NULL;
 	char *ret = NULL;
 
-	dir_path = state_path(PERFCOUNTDIR);
+	dir_path = state_path(talloc_tos(), PERFCOUNTDIR);
 	if (dir_path == NULL) {
 		return NULL;
 	}
@@ -64,7 +64,7 @@ static char *counters_directory(const char *dbname)
 		return NULL;
 	}
 
-	ret = state_path(db_subpath);
+	ret = state_path(talloc_tos(), db_subpath);
 	TALLOC_FREE(dir_path);
 	return ret;
 }
diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c
index 4f365662a71..b49d5f43381 100644
--- a/source3/utils/net_idmap.c
+++ b/source3/utils/net_idmap.c
@@ -148,7 +148,7 @@ static char *net_idmap_dbfile(struct net_context *c,
 			d_fprintf(stderr, _("Out of memory!\n"));
 		}
 	} else if (strequal(backend, "tdb")) {
-		dbfile = state_path("winbindd_idmap.tdb");
+		dbfile = state_path(talloc_tos(), "winbindd_idmap.tdb");
 		if (dbfile == NULL) {
 			d_fprintf(stderr, _("Out of memory!\n"));
 		}
@@ -161,7 +161,7 @@ static char *net_idmap_dbfile(struct net_context *c,
 		}
 		ctx->backend = TDB;
 	} else if (strequal(backend, "autorid")) {
-		dbfile = state_path("autorid.tdb");
+		dbfile = state_path(talloc_tos(), "autorid.tdb");
 		if (dbfile == NULL) {
 			d_fprintf(stderr, _("Out of memory!\n"));
 		}
diff --git a/source3/utils/net_registry.c b/source3/utils/net_registry.c
index c67a148ddd0..01a36b20e7c 100644
--- a/source3/utils/net_registry.c
+++ b/source3/utils/net_registry.c
@@ -1512,7 +1512,7 @@ static int net_registry_check(struct net_context *c, int argc,
 	} else if (argc > 0) {
 		dbfile = talloc_strdup(talloc_tos(), argv[0]);
 	} else {
-		dbfile = state_path("registry.tdb");
+		dbfile = state_path(talloc_tos(), "registry.tdb");
 	}
 	if (dbfile == NULL) {
 		return -1;
diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c
index bd89b9ebf0a..6e612e9dd8f 100644
--- a/source3/utils/smbcontrol.c
+++ b/source3/utils/smbcontrol.c
@@ -1061,7 +1061,7 @@ static bool do_winbind_online(struct tevent_context *ev_ctx,
 		return False;
 	}
 
-	db_path = state_path("winbindd_cache.tdb");
+	db_path = state_path(talloc_tos(), "winbindd_cache.tdb");
 	if (db_path == NULL) {
 		return false;
 	}
@@ -1099,7 +1099,7 @@ static bool do_winbind_offline(struct tevent_context *ev_ctx,
 		return False;
 	}
 
-	db_path = state_path("winbindd_cache.tdb");
+	db_path = state_path(talloc_tos(), "winbindd_cache.tdb");
 	if (db_path == NULL) {
 		return false;
 	}
diff --git a/source3/winbindd/idmap_autorid.c b/source3/winbindd/idmap_autorid.c
index 65b3d5af222..cb7dcba1a5f 100644
--- a/source3/winbindd/idmap_autorid.c
+++ b/source3/winbindd/idmap_autorid.c
@@ -879,7 +879,7 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
 	commonconfig->rw_ops->get_new_id = idmap_autorid_allocate_id;
 	commonconfig->rw_ops->set_mapping = idmap_tdb_common_set_mapping;
 
-	db_path = state_path("autorid.tdb");
+	db_path = state_path(talloc_tos(), "autorid.tdb");
 	if (db_path == NULL) {
 		status = NT_STATUS_NO_MEMORY;
 		goto error;
diff --git a/source3/winbindd/idmap_tdb.c b/source3/winbindd/idmap_tdb.c
index 24ef11836e1..b1f908e2d62 100644
--- a/source3/winbindd/idmap_tdb.c
+++ b/source3/winbindd/idmap_tdb.c
@@ -310,7 +310,7 @@ static NTSTATUS idmap_tdb_open_db(struct idmap_domain *dom)
 	mem_ctx = talloc_stackframe();
 
 	/* use the old database if present */
-	tdbfile = state_path("winbindd_idmap.tdb");
+	tdbfile = state_path(talloc_tos(), "winbindd_idmap.tdb");
 	if (!tdbfile) {
 		DEBUG(0, ("Out of memory!\n"));
 		ret = NT_STATUS_NO_MEMORY;
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index 5e273762ff1..b63db381540 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -1256,7 +1256,7 @@ static void winbindd_listen_fde_handler(struct tevent_context *ev,
 
 char *get_winbind_priv_pipe_dir(void)
 {
-	return state_path(WINBINDD_PRIV_SOCKET_SUBDIR);
+	return state_path(talloc_tos(), WINBINDD_PRIV_SOCKET_SUBDIR);
 }
 
 static void winbindd_setup_max_fds(void)
diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index af67aa3b0cf..2f3bac7587b 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -119,7 +119,7 @@ static char *wcache_path(void)
 	 * Data needs to be kept persistent in state directory for
 	 * running with "winbindd offline logon".
 	 */
-	return state_path("winbindd_cache.tdb");
+	return state_path(talloc_tos(), "winbindd_cache.tdb");
 }
 
 static void winbindd_domain_init_backend(struct winbindd_domain *domain)
-- 
2.11.0


From b51168ffd551a844ce1bed93592bb7a31323907d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 16 Aug 2018 10:51:44 +0200
Subject: [PATCH 5/5] lib: Pass mem_ctx to cache_path()

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 at samba.org>
---
 libgpo/pygpo.c                   | 2 +-
 source3/lib/gencache.c           | 2 +-
 source3/lib/util_path.c          | 4 ++--
 source3/lib/util_path.h          | 2 +-
 source3/libgpo/gpext/registry.c  | 2 +-
 source3/libgpo/gpext/scripts.c   | 2 +-
 source3/libgpo/gpext/security.c  | 2 +-
 source3/libsmb/samlogon_cache.c  | 2 +-
 source3/nmbd/nmbd_serverlistdb.c | 2 +-
 source3/passdb/login_cache.c     | 2 +-
 source3/printing/printing.c      | 4 ++--
 source3/printing/printing_db.c   | 2 +-
 source3/profile/profile.c        | 2 +-
 source3/smbd/lanman.c            | 2 +-
 source3/utils/net_ads_gpo.c      | 2 +-
 15 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c
index 88486424917..cd107318860 100644
--- a/libgpo/pygpo.c
+++ b/libgpo/pygpo.c
@@ -93,7 +93,7 @@ static PyObject *py_gpo_get_unix_path(PyObject *self, PyObject *args,
 	}
 
 	if (!cache_dir) {
-		cache_dir = cache_path(GPO_CACHE_DIR);
+		cache_dir = cache_path(talloc_tos(), GPO_CACHE_DIR);
 		if (!cache_dir) {
 			PyErr_SetString(PyExc_MemoryError,
 					"Failed to determine gpo cache dir");
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index 158554bd9a8..b4d374bf837 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -64,7 +64,7 @@ static bool gencache_init(void)
 
 	hash_size = lp_parm_int(-1, "gencache", "hash_size", 10000);
 
-	cache_fname = cache_path("gencache.tdb");
+	cache_fname = cache_path(talloc_tos(), "gencache.tdb");
 	if (cache_fname == NULL) {
 		return false;
 	}
diff --git a/source3/lib/util_path.c b/source3/lib/util_path.c
index efe3e608d7d..d9fed29c2a5 100644
--- a/source3/lib/util_path.c
+++ b/source3/lib/util_path.c
@@ -91,9 +91,9 @@ char *state_path(TALLOC_CTX *mem_ctx, const char *name)
  * @retval Pointer to a talloc'ed string containing the full path.
  **/
 
-char *cache_path(const char *name)
+char *cache_path(TALLOC_CTX *mem_ctx, const char *name)
 {
-	return xx_path(talloc_tos(), name, lp_cache_directory());
+	return xx_path(mem_ctx, name, lp_cache_directory());
 }
 
 /**
diff --git a/source3/lib/util_path.h b/source3/lib/util_path.h
index b189b3e33cb..3e7d04de550 100644
--- a/source3/lib/util_path.h
+++ b/source3/lib/util_path.h
@@ -29,7 +29,7 @@
 
 char *lock_path(TALLOC_CTX *mem_ctx, const char *name);
 char *state_path(TALLOC_CTX *mem_ctx, const char *name);
-char *cache_path(const char *name);
+char *cache_path(TALLOC_CTX *mem_ctx, const char *name);
 char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *abs_path);
 
 #endif
diff --git a/source3/libgpo/gpext/registry.c b/source3/libgpo/gpext/registry.c
index 5d51bdff6e9..525493fcb2c 100644
--- a/source3/libgpo/gpext/registry.c
+++ b/source3/libgpo/gpext/registry.c
@@ -291,7 +291,7 @@ static NTSTATUS registry_process_group_policy(TALLOC_CTX *mem_ctx,
 	size_t num_entries = 0;
 	char *unix_path = NULL;
 	const struct GROUP_POLICY_OBJECT *gpo;
-	char *gpo_cache_path = cache_path(GPO_CACHE_DIR);
+	char *gpo_cache_path = cache_path(talloc_tos(), GPO_CACHE_DIR);
 	if (gpo_cache_path == NULL) {
 		return NT_STATUS_NO_MEMORY;
 	}
diff --git a/source3/libgpo/gpext/scripts.c b/source3/libgpo/gpext/scripts.c
index de664133b87..dfa9958e326 100644
--- a/source3/libgpo/gpext/scripts.c
+++ b/source3/libgpo/gpext/scripts.c
@@ -364,7 +364,7 @@ static NTSTATUS scripts_process_group_policy(TALLOC_CTX *mem_ctx,
 		GP_SCRIPTS_INI_LOGOFF
 	};
 	const struct GROUP_POLICY_OBJECT *gpo;
-	char *gpo_cache_path = cache_path(GPO_CACHE_DIR);
+	char *gpo_cache_path = cache_path(talloc_tos(), GPO_CACHE_DIR);
 	if (gpo_cache_path == NULL) {
 		return NT_STATUS_NO_MEMORY;
 	}
diff --git a/source3/libgpo/gpext/security.c b/source3/libgpo/gpext/security.c
index b6b7ca08e62..a915eec61e4 100644
--- a/source3/libgpo/gpext/security.c
+++ b/source3/libgpo/gpext/security.c
@@ -154,7 +154,7 @@ static NTSTATUS security_process_group_policy(TALLOC_CTX *mem_ctx,
 	char *unix_path = NULL;
 	struct gp_inifile_context *ini_ctx = NULL;
 	const struct GROUP_POLICY_OBJECT *gpo;
-	char *gpo_cache_path = cache_path(GPO_CACHE_DIR);
+	char *gpo_cache_path = cache_path(talloc_tos(), GPO_CACHE_DIR);
 	if (gpo_cache_path == NULL) {
 		return NT_STATUS_NO_MEMORY;
 	}
diff --git a/source3/libsmb/samlogon_cache.c b/source3/libsmb/samlogon_cache.c
index ae77610ec99..74e89d7c38b 100644
--- a/source3/libsmb/samlogon_cache.c
+++ b/source3/libsmb/samlogon_cache.c
@@ -51,7 +51,7 @@ bool netsamlogon_cache_init(void)
 		return true;
 	}
 
-	path = cache_path(NETSAMLOGON_TDB);
+	path = cache_path(talloc_tos(), NETSAMLOGON_TDB);
 	if (path == NULL) {
 		return false;
 	}
diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c
index 05dcb6c7482..ad251833ed5 100644
--- a/source3/nmbd/nmbd_serverlistdb.c
+++ b/source3/nmbd/nmbd_serverlistdb.c
@@ -300,7 +300,7 @@ void write_browse_list(time_t t, bool force_write)
 
 	updatecount++;
 
-	fname = cache_path(SERVER_LIST);
+	fname = cache_path(talloc_tos(), SERVER_LIST);
 	if (!fname) {
 		return;
 	}
diff --git a/source3/passdb/login_cache.c b/source3/passdb/login_cache.c
index eebb50a8b13..6b636b3c8b7 100644
--- a/source3/passdb/login_cache.c
+++ b/source3/passdb/login_cache.c
@@ -38,7 +38,7 @@ bool login_cache_init(void)
 	/* skip file open if it's already opened */
 	if (cache) return True;
 
-	cache_fname = cache_path(LOGIN_CACHE_FILE);
+	cache_fname = cache_path(talloc_tos(), LOGIN_CACHE_FILE);
 	if (cache_fname == NULL) {
 		DEBUG(0, ("Filename allocation failed.\n"));
 		return False;
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index 0acbb7e28ce..efdd6870999 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -204,7 +204,7 @@ bool print_backend_init(struct messaging_context *msg_ctx)
 		return false;
 	}
 
-	print_cache_path = cache_path("printing");
+	print_cache_path = cache_path(talloc_tos(), "printing");
 	if (print_cache_path == NULL) {
 		return false;
 	}
@@ -214,7 +214,7 @@ bool print_backend_init(struct messaging_context *msg_ctx)
 		return false;
 	}
 
-	print_cache_path = cache_path("printing.tdb");
+	print_cache_path = cache_path(talloc_tos(), "printing.tdb");
 	if (print_cache_path == NULL) {
 		return false;
 	}
diff --git a/source3/printing/printing_db.c b/source3/printing/printing_db.c
index 7465195b771..3fa85579f20 100644
--- a/source3/printing/printing_db.c
+++ b/source3/printing/printing_db.c
@@ -95,7 +95,7 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
 		DLIST_ADD(print_db_head, p);
 	}
 
-	print_cache_path = cache_path("printing/");
+	print_cache_path = cache_path(talloc_tos(), "printing/");
 	if (print_cache_path == NULL) {
 		DLIST_REMOVE(print_db_head, p);
 		SAFE_FREE(p);
diff --git a/source3/profile/profile.c b/source3/profile/profile.c
index 833c9c4425d..5deef81b6df 100644
--- a/source3/profile/profile.c
+++ b/source3/profile/profile.c
@@ -129,7 +129,7 @@ bool profile_setup(struct messaging_context *msg_ctx, bool rdonly)
 		return true;
 	}
 
-	db_name = cache_path("smbprofile.tdb");
+	db_name = cache_path(talloc_tos(), "smbprofile.tdb");
 	if (db_name == NULL) {
 		return false;
 	}
diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c
index 90906a204d4..dcc7f916d6e 100644
--- a/source3/smbd/lanman.c
+++ b/source3/smbd/lanman.c
@@ -1228,7 +1228,7 @@ static int get_session_info(uint32_t servertype,
 	char **lines;
 	bool local_list_only;
 	int i;
-	char *slist_cache_path = cache_path(SERVER_LIST);
+	char *slist_cache_path = cache_path(talloc_tos(), SERVER_LIST);
 	if (slist_cache_path == NULL) {
 		return 0;
 	}
diff --git a/source3/utils/net_ads_gpo.c b/source3/utils/net_ads_gpo.c
index f2f65c8790e..791e836bfd9 100644
--- a/source3/utils/net_ads_gpo.c
+++ b/source3/utils/net_ads_gpo.c
@@ -100,7 +100,7 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
 	d_printf(_("finished\n"));
 
 	d_printf(_("* Refreshing Group Policy Data "));
-	gpo_cache_path = cache_path(GPO_CACHE_DIR);
+	gpo_cache_path = cache_path(talloc_tos(), GPO_CACHE_DIR);
 	if (gpo_cache_path == NULL) {
 		d_printf(_("failed: %s\n"), nt_errstr(NT_STATUS_NO_MEMORY));
 		goto out;
-- 
2.11.0



More information about the samba-technical mailing list