From c3e88f00e0263bfbb232973578edfc3a28a5d377 Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Thu, 19 Jun 2014 12:23:26 +0100
Subject: [PATCH 23/45] SYSDB: sysdb_search_custom fix memory leak
Add temporally talloc context to allocate basedn on.
Reviewed-by: Stephen Gallagher <sgallagh@redhat.com>
(cherry picked from commit a4caef931a245fb3c44b70ea65a58bd0c1ff8dc4)
---
src/db/sysdb_ops.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 3a41f514aef1f1cd5612180963df397127b85188..379d0f8eb91a1fe0199e1128d553cd67562daf00 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -2235,26 +2235,38 @@ int sysdb_search_custom(TALLOC_CTX *mem_ctx,
size_t *msgs_count,
struct ldb_message ***msgs)
{
- struct ldb_dn *basedn;
+ TALLOC_CTX *tmp_ctx;
+ struct ldb_dn *basedn = NULL;
int ret;
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
if (filter == NULL || subtree_name == NULL) {
- return EINVAL;
+ ret = EINVAL;
+ goto done;
}
- basedn = sysdb_custom_subtree_dn(sysdb, mem_ctx, domain, subtree_name);
+ basedn = sysdb_custom_subtree_dn(sysdb, tmp_ctx, domain, subtree_name);
if (basedn == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_custom_subtree_dn failed.\n");
- return ENOMEM;
+ ret = ENOMEM;
+ goto done;
}
if (!ldb_dn_validate(basedn)) {
DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create DN.\n");
- return EINVAL;
+ ret = EINVAL;
+ goto done;
}
ret = sysdb_search_entry(mem_ctx, sysdb, basedn,
LDB_SCOPE_SUBTREE, filter, attrs,
msgs_count, msgs);
+done:
+ talloc_free(tmp_ctx);
return ret;
}
--
2.4.3