summaryrefslogtreecommitdiffstats
path: root/source4
diff options
context:
space:
mode:
authorMatthias Dieter Wallnöfer <mdw@samba.org>2010-06-29 15:52:19 +0200
committerMatthias Dieter Wallnöfer <mdw@samba.org>2010-07-01 15:48:04 +0200
commitd0e877e785f6463dadbb973bc42174674cbdbad2 (patch)
tree5b94c85d0dcb8f1e52d0241db61f3344765f0957 /source4
parente4ba8fb3b9a6eebe7a56179f67d1aeff64cf1abc (diff)
downloadsamba-d0e877e785f6463dadbb973bc42174674cbdbad2.tar.gz
samba-d0e877e785f6463dadbb973bc42174674cbdbad2.tar.xz
samba-d0e877e785f6463dadbb973bc42174674cbdbad2.zip
s4:lib/registry/ldb.c - "ldb_add_key" - fix talloc handling
- free "msg" when possible - prevent "talloc_strdup"s where not necessary
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/registry/ldb.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c
index 2b084456660..67a0c890f76 100644
--- a/source4/lib/registry/ldb.c
+++ b/source4/lib/registry/ldb.c
@@ -586,6 +586,7 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
struct hive_key **newkey)
{
struct ldb_key_data *parentkd = discard_const_p(struct ldb_key_data, parent);
+ struct ldb_dn *ldb_path;
struct ldb_message *msg;
struct ldb_key_data *newkd;
int ret;
@@ -594,18 +595,23 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
return WERR_INVALID_PARAM;
}
+ ldb_path = reg_path_to_ldb(mem_ctx, parent, name, NULL);
+ W_ERROR_HAVE_NO_MEMORY(ldb_path);
+
msg = ldb_msg_new(mem_ctx);
W_ERROR_HAVE_NO_MEMORY(msg);
- msg->dn = reg_path_to_ldb(msg, parent, name, NULL);
- W_ERROR_HAVE_NO_MEMORY(msg->dn);
+ msg->dn = ldb_path;
- ldb_msg_add_string(msg, "key", talloc_strdup(mem_ctx, name));
- if (classname != NULL)
- ldb_msg_add_string(msg, "classname",
- talloc_strdup(mem_ctx, classname));
+ ldb_msg_add_string(msg, "key", name);
+ if (classname != NULL) {
+ ldb_msg_add_string(msg, "classname", classname);
+ }
ret = ldb_add(parentkd->ldb, msg);
+
+ talloc_free(msg);
+
if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) {
return WERR_ALREADY_EXISTS;
}
@@ -615,13 +621,13 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
return WERR_FOOBAR;
}
- DEBUG(2, ("key added: %s\n", ldb_dn_get_linearized(msg->dn)));
+ DEBUG(2, ("key added: %s\n", ldb_dn_get_linearized(ldb_path)));
newkd = talloc_zero(mem_ctx, struct ldb_key_data);
W_ERROR_HAVE_NO_MEMORY(newkd);
newkd->ldb = talloc_reference(newkd, parentkd->ldb);
newkd->key.ops = &reg_backend_ldb;
- newkd->dn = talloc_steal(newkd, msg->dn);
+ newkd->dn = talloc_steal(newkd, ldb_path);
newkd->classname = talloc_steal(newkd, classname);
*newkey = (struct hive_key *)newkd;