https://fedorahosted.org/sssd/ticket/2869
From c38cae6eef560028c54ad135b4f3a4bead30263f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com> Date: Tue, 16 Feb 2016 13:14:00 +0100 Subject: [PATCH 1/5] cache_req tests: remove unused users and groups
--- src/tests/cmocka/test_responder_cache_req.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c index 842f94a72b0d5c3c7b3b47f541bd9b00f7038d46..770c7d02b2cc83a1e579cc4b2247273ebfa212bc 100644 --- a/src/tests/cmocka/test_responder_cache_req.c +++ b/src/tests/cmocka/test_responder_cache_req.c @@ -44,11 +44,6 @@ #define TEST_GROUP_NAME2 "test_group2" #define TEST_GROUP_ID2 1001 -#define TEST_USER_ID3 1002 -#define TEST_USER_NAME3 "test_user3" -#define TEST_GROUP_NAME3 "test_group3" -#define TEST_GROUP_ID3 1002 - #define TEST_USER_PREFIX "test*" #define new_single_domain_test(test) \ @@ -1340,12 +1335,6 @@ void test_users_by_recent_filter_valid(void **state) test_ctx->create_user1 = true; test_ctx->create_user2 = true; - ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME3, - "pwd", 1002, 1002, NULL, NULL, NULL, - "cn="TEST_USER_NAME3",dc=test", - NULL, NULL, 1000, time(NULL)-1); - assert_int_equal(ret, EOK); - req_mem_ctx = talloc_new(test_ctx->tctx); check_leaks_push(req_mem_ctx); -- 2.1.0
From f61d0192b8254247802167ea385b52f65d4e175d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com> Date: Thu, 18 Feb 2016 14:25:18 +0100 Subject: [PATCH 2/5] sysdb: reset ldb errors After ldb connect ldb context contains the following error: "NULL Base DN invalid for a base search" This comes from internal ldb function ldb_set_default_dns() which runs base search on NULL dn to discover records similar to what rootDSE provides. However, tdb backend considers this an error and sets the message above. This may break memory leak checks in tests when we do push/pop on test_ctx which is a indirect parent of ldb_context. The error message is allocated when push is called but it is freed by other ldb queries and therefore not preset during the push phase and thus the leak check fails. --- src/db/sysdb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/db/sysdb.c b/src/db/sysdb.c index d4366a3c76f114bf113567754a1e0417afe664e3..8bed770818c04cbc0b5f85f83baef5671c5bb80a 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -26,6 +26,7 @@ #include "db/sysdb_private.h" #include "confdb/confdb.h" #include <time.h> +#include <ldb_module.h> #define LDB_MODULES_PATH "LDB_MODULES_PATH" @@ -61,6 +62,9 @@ errno_t sysdb_ldb_connect(TALLOC_CTX *mem_ctx, const char *filename, return EIO; } + /* reset ldb error if any */ + ldb_reset_err_string(ldb); + *_ldb = ldb; return EOK; -- 2.1.0
From 7a28c8caf391417eefa309021d6f1ee491101f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com> Date: Wed, 17 Feb 2016 10:07:18 +0100 Subject: [PATCH 3/5] cache_req tests: use leak check in test fixtures To ensure no memory is leak on long living context such as rctx. Resolves: https://fedorahosted.org/sssd/ticket/2869 --- src/tests/cmocka/test_responder_cache_req.c | 67 +++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c index 770c7d02b2cc83a1e579cc4b2247273ebfa212bc..d2a2a61bb3526801b1f7518904d2f82d01cbaecd 100644 --- a/src/tests/cmocka/test_responder_cache_req.c +++ b/src/tests/cmocka/test_responder_cache_req.c @@ -188,6 +188,8 @@ static void prepare_concrete_user(TALLOC_CTX *mem_ctx, "cn=test-user,dc=test", attrs, NULL, timeout, transaction_time); assert_int_equal(ret, EOK); + + talloc_free(attrs); } static void prepare_user(TALLOC_CTX *mem_ctx, @@ -359,9 +361,11 @@ static int test_single_domain_setup(void **state) struct cache_req_test_ctx *test_ctx = NULL; errno_t ret; + assert_true(leak_check_setup()); + test_dom_suite_setup(TESTS_PATH); - test_ctx = talloc_zero(NULL, struct cache_req_test_ctx); + test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx); assert_non_null(test_ctx); *state = test_ctx; @@ -375,13 +379,25 @@ static int test_single_domain_setup(void **state) ret = sss_ncache_init(test_ctx, &test_ctx->ncache); assert_int_equal(ret, EOK); + + check_leaks_push(test_ctx); + return 0; } static int test_single_domain_teardown(void **state) { - talloc_zfree(*state); + struct cache_req_test_ctx *test_ctx; + + test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx); + + talloc_zfree(test_ctx->result); + talloc_zfree(test_ctx->name); + + assert_true(check_leaks_pop(test_ctx)); + talloc_zfree(test_ctx); test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME); + assert_true(leak_check_teardown()); return 0; } @@ -390,9 +406,11 @@ static int test_multi_domain_setup(void **state) struct cache_req_test_ctx *test_ctx = NULL; errno_t ret; + assert_true(leak_check_setup()); + test_dom_suite_setup(TESTS_PATH); - test_ctx = talloc_zero(NULL, struct cache_req_test_ctx); + test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx); assert_non_null(test_ctx); *state = test_ctx; @@ -407,13 +425,25 @@ static int test_multi_domain_setup(void **state) ret = sss_ncache_init(test_ctx, &test_ctx->ncache); assert_int_equal(ret, EOK); + + check_leaks_push(test_ctx); + return 0; } static int test_multi_domain_teardown(void **state) { - talloc_zfree(*state); + struct cache_req_test_ctx *test_ctx; + + test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx); + + talloc_zfree(test_ctx->result); + talloc_zfree(test_ctx->name); + + assert_true(check_leaks_pop(test_ctx)); + talloc_zfree(test_ctx); test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains); + assert_true(leak_check_teardown()); return 0; } @@ -516,6 +546,8 @@ void test_user_by_name_multiple_domains_parse(void **state) assert_non_null(test_ctx->name); assert_string_equal(name, test_ctx->name); + + talloc_free(fqn); } void test_user_by_name_cache_valid(void **state) @@ -524,6 +556,9 @@ void test_user_by_name_cache_valid(void **state) test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx); + /* leak on rctx */ + //talloc_zero(test_ctx->rctx, char); + /* Setup user. */ prepare_user(test_ctx, test_ctx->tctx->dom, 1000, time(NULL)); @@ -1014,6 +1049,8 @@ void test_group_by_name_multiple_domains_parse(void **state) assert_non_null(test_ctx->name); assert_string_equal(name, test_ctx->name); + + talloc_free(fqn); } void test_group_by_name_cache_valid(void **state) @@ -1326,9 +1363,9 @@ void test_users_by_recent_filter_valid(void **state) struct cache_req_test_ctx *test_ctx = NULL; TALLOC_CTX *req_mem_ctx = NULL; struct tevent_req *req = NULL; - const char **user_names = NULL; - const char **ldb_results = NULL; - const char *ldbname = NULL; + size_t num_users = 2; + const char *user_names[num_users]; + const char *ldb_results[num_users]; errno_t ret; test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx); @@ -1358,23 +1395,19 @@ void test_users_by_recent_filter_valid(void **state) assert_non_null(test_ctx->result); assert_int_equal(test_ctx->result->count, 2); - user_names = talloc_array(test_ctx, const char *, 2); - assert_non_null(user_names); user_names[0] = TEST_USER_NAME; user_names[1] = TEST_USER_NAME2; - ldb_results = talloc_array(test_ctx, const char *, 2); - assert_non_null(ldb_results); - for (int i = 0; i < 2; ++i) { - ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[i], - SYSDB_NAME, NULL); - assert_non_null(ldbname); - ldb_results[i] = ldbname; + for (int i = 0; i < num_users; ++i) { + ldb_results[i] = ldb_msg_find_attr_as_string(test_ctx->result->msgs[i], + SYSDB_NAME, NULL); + assert_non_null(ldb_results[i]); } assert_string_not_equal(ldb_results[0], ldb_results[1]); - assert_true(tc_are_values_in_array(user_names, ldb_results)); + assert_true(are_values_in_array(user_names, num_users, + ldb_results, num_users)); } void test_users_by_filter_filter_old(void **state) -- 2.1.0
_______________________________________________ sssd-devel mailing list sssd-devel@lists.fedorahosted.org https://lists.fedorahosted.org/admin/lists/sssd-devel@lists.fedorahosted.org