[PATCH 11/27] net_registry: don't leak state_path onto talloc tos

David Disseldorp ddiss at samba.org
Sun Nov 2 12:21:33 MST 2014


Signed-off-by: David Disseldorp <ddiss at samba.org>
---
 source3/utils/net_registry.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/source3/utils/net_registry.c b/source3/utils/net_registry.c
index 0993b95..befc73c 100644
--- a/source3/utils/net_registry.c
+++ b/source3/utils/net_registry.c
@@ -1484,8 +1484,9 @@ static int net_registry_convert(struct net_context *c, int argc,
 static int net_registry_check(struct net_context *c, int argc,
 			      const char **argv)
 {
-	const char *dbfile;
+	char *dbfile;
 	struct check_options opts;
+	int ret;
 
 	if (argc > 1|| c->display_usage) {
 		d_printf("%s\n%s",
@@ -1505,9 +1506,13 @@ static int net_registry_check(struct net_context *c, int argc,
 		return c->display_usage ? 0 : -1;
 	}
 
-	dbfile = c->opt_db ? c->opt_db : (
-		(argc > 0) ? argv[0] :
-		state_path("registry.tdb"));
+	if (c->opt_db != NULL) {
+		dbfile = talloc_strdup(talloc_tos(), c->opt_db);
+	} else if (argc > 0) {
+		dbfile = talloc_strdup(talloc_tos(), argv[0]);
+	} else {
+		dbfile = state_path("registry.tdb");
+	}
 	if (dbfile == NULL) {
 		return -1;
 	}
@@ -1525,7 +1530,9 @@ static int net_registry_check(struct net_context *c, int argc,
 		.implicit_db = (c->opt_db == NULL) && (argc == 0),
 	};
 
-	return net_registry_check_db(dbfile, &opts);
+	ret = net_registry_check_db(dbfile, &opts);
+	talloc_free(dbfile);
+	return ret;
 }
 
 
-- 
1.8.4.5



More information about the samba-technical mailing list