From: Sebastian Harl Date: Fri, 7 Mar 2014 13:52:59 +0000 (+0100) Subject: utils llist: Let llist_get() increment the reference count. X-Git-Tag: sysdb-0.1.0~172 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8fae96642304f80a5ce343626970b1cff87123f2;p=sysdb.git utils llist: Let llist_get() increment the reference count. This feels more consistent. --- diff --git a/src/frontend/connection.c b/src/frontend/connection.c index b48de2c..fdbb26f 100644 --- a/src/frontend/connection.c +++ b/src/frontend/connection.c @@ -301,8 +301,10 @@ command_handle(sdb_conn_t *conn) node = SDB_CONN_NODE(sdb_llist_get(parsetree, 0)); } - if (node) + if (node) { status = sdb_fe_exec(conn, node); + sdb_object_deref(SDB_OBJ(node)); + } sdb_llist_destroy(parsetree); break; diff --git a/src/frontend/parser.c b/src/frontend/parser.c index e8c0cde..6504a66 100644 --- a/src/frontend/parser.c +++ b/src/frontend/parser.c @@ -121,6 +121,7 @@ sdb_fe_parse_matcher(const char *expr, int len) m = NULL; sdb_llist_destroy(yyextra.parsetree); + sdb_object_deref(SDB_OBJ(node)); return m; } /* sdb_fe_parse_matcher */ diff --git a/src/include/utils/llist.h b/src/include/utils/llist.h index 3eefae5..9356190 100644 --- a/src/include/utils/llist.h +++ b/src/include/utils/llist.h @@ -121,7 +121,9 @@ sdb_llist_insert_sorted(sdb_llist_t *list, /* * sdb_llist_get: - * Returns the i-th element of the list or NULL in case of an error. + * Returns the i-th element of the list or NULL in case of an error. The + * reference count of the element is incremented before returning it to share + * ownership between the list and the caller. */ sdb_object_t * sdb_llist_get(sdb_llist_t *list, size_t i); diff --git a/src/utils/llist.c b/src/utils/llist.c index 2dc7781..f009bcd 100644 --- a/src/utils/llist.c +++ b/src/utils/llist.c @@ -321,6 +321,7 @@ sdb_llist_get(sdb_llist_t *list, size_t i) /* iterate */; assert(elem); + sdb_object_ref(elem->obj); return elem->obj; } /* sdb_llist_get */ diff --git a/t/frontend/parser_test.c b/t/frontend/parser_test.c index 64580b9..acd8ee6 100644 --- a/t/frontend/parser_test.c +++ b/t/frontend/parser_test.c @@ -91,6 +91,7 @@ START_TEST(test_parse) "sdb_fe_parse(LIST)->cmd = %i; expected: %d " "(CONNECTION_LIST)", SDB_CONN_NODE(obj)->cmd, CONNECTION_LIST); + sdb_object_deref(obj); } sdb_llist_destroy(check); diff --git a/t/utils/llist_test.c b/t/utils/llist_test.c index 5197bd1..9539c91 100644 --- a/t/utils/llist_test.c +++ b/t/utils/llist_test.c @@ -179,9 +179,10 @@ START_TEST(test_sdb_llist_get) fail_unless(check == &golden_data[i], "sdb_llist_get() = NULL; expected: %p", &golden_data[i]); - fail_unless(check->ref_cnt == 2, - "sdb_llist_get() changed reference count; got: %i; " - "expected: 2", check->ref_cnt); + fail_unless(check->ref_cnt == 3, + "sdb_llist_get() didn't increment reference count; got: %i; " + "expected: 3", check->ref_cnt); + sdb_object_deref(check); } } END_TEST