diff options
author | Pavel Reichl <preichl@redhat.com> | 2014-06-19 12:09:06 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-06-20 10:37:37 +0200 |
commit | 09579ae252c181c7884defc0612c36108f6cf509 (patch) | |
tree | c55475e1546aa573dadb807dfe2aff4dc07d4212 /src/db | |
parent | af63cdbfe0c917e0dc921232f67295fdc48d1e32 (diff) | |
download | sssd-09579ae252c181c7884defc0612c36108f6cf509.tar.gz sssd-09579ae252c181c7884defc0612c36108f6cf509.tar.xz sssd-09579ae252c181c7884defc0612c36108f6cf509.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>
Diffstat (limited to 'src/db')
-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 dd14190bf..1057090e6 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -505,8 +505,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 1f51b9682..500860f48 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============================================ */ |