diff options
author | Pavel Reichl <preichl@redhat.com> | 2014-06-19 12:09:06 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2015-06-19 14:09:44 +0200 |
commit | 4b9a43bda65f8950e92bc86474883ff27caa27d6 (patch) | |
tree | b55e2eb7a4796bc12667bdf617bce82d55da584f | |
parent | 3d2ef573962249d8570eead56aed8057839cbc5a (diff) | |
download | sssd-4b9a43bda65f8950e92bc86474883ff27caa27d6.tar.gz sssd-4b9a43bda65f8950e92bc86474883ff27caa27d6.tar.xz sssd-4b9a43bda65f8950e92bc86474883ff27caa27d6.zip |
SYSDB: sysdb_search_entry fix memory leak
Allocate res on tmp_ctx instead of on mem_ctx.
Also use '_' prefix convention for output parameters.
Reviewed-by: Stephen Gallagher <sgallagh@redhat.com>
(cherry picked from commit 09579ae252c181c7884defc0612c36108f6cf509)
-rw-r--r-- | src/db/sysdb.h | 4 | ||||
-rw-r--r-- | src/db/sysdb_ops.c | 29 |
2 files changed, 22 insertions, 11 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 510687495..1bb5fb861 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -516,8 +516,8 @@ int sysdb_search_entry(TALLOC_CTX *mem_ctx, int scope, const char *filter, const char **attrs, - size_t *msgs_count, - struct ldb_message ***msgs); + size_t *_msgs_count, + struct ldb_message ***_msgs); /* Search User (by uid, sid or name) */ int sysdb_search_user_by_name(TALLOC_CTX *mem_ctx, diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index 355967311..3a41f514a 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -211,27 +211,38 @@ int sysdb_search_entry(TALLOC_CTX *mem_ctx, int scope, const char *filter, const char **attrs, - size_t *msgs_count, - struct ldb_message ***msgs) + size_t *_msgs_count, + struct ldb_message ***_msgs) { + TALLOC_CTX *tmp_ctx; struct ldb_result *res; int ret; - ret = ldb_search(sysdb->ldb, mem_ctx, &res, + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + ret = ENOMEM; + goto done; + } + + ret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn, scope, attrs, filter?"%s":NULL, filter); - if (ret) { - return sysdb_error_to_errno(ret); + if (ret != EOK) { + ret = sysdb_error_to_errno(ret); + goto done; } - *msgs_count = res->count; - *msgs = talloc_steal(mem_ctx, res->msgs); + *_msgs_count = res->count; + *_msgs = talloc_steal(mem_ctx, res->msgs); if (res->count == 0) { - return ENOENT; + ret = ENOENT; + goto done; } - return EOK; +done: + talloc_zfree(tmp_ctx); + return ret; } /* =Search-Entry-by-SID-string============================================ */ |