summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e7edc64)
raw | patch | inline | side by side (parent: e7edc64)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 7 Mar 2014 13:52:59 +0000 (14:52 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 7 Mar 2014 13:52:59 +0000 (14:52 +0100) |
This feels more consistent.
index b48de2c893ccbc9d9c65de335fecbb66c3421733..fdbb26fe60518a0b1834d4c809a3f27915f54d74 100644 (file)
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 e8c0cdef314c7b186110f578ec3ab84f6f9cf908..6504a66ea7a408b00522ab3ae94639f52e484df0 100644 (file)
--- a/src/frontend/parser.c
+++ b/src/frontend/parser.c
m = NULL;
sdb_llist_destroy(yyextra.parsetree);
+ sdb_object_deref(SDB_OBJ(node));
return m;
} /* sdb_fe_parse_matcher */
index 3eefae5e19b894adf457a5d195e7840a11f79757..93561906b6056a272f468c9c87187469004b8246 100644 (file)
/*
* 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 2dc7781cccab7f2ca8decd373461ae7e42999d0b..f009bcdac43cd30b3ccd51c0d79f953018f16e04 100644 (file)
--- a/src/utils/llist.c
+++ b/src/utils/llist.c
/* iterate */;
assert(elem);
+ sdb_object_ref(elem->obj);
return elem->obj;
} /* sdb_llist_get */
index 64580b9e70412aebc8800f599da6bc52f6f5d960..acd8ee69f079c5571be0b4786ef8ec9c647436fe 100644 (file)
--- a/t/frontend/parser_test.c
+++ b/t/frontend/parser_test.c
"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 5197bd11cf05079efcbc5e9b9c1dcaab0aeab4dc..9539c910bc9acbe3c73b8ba62d4f9c47e695380b 100644 (file)
--- a/t/utils/llist_test.c
+++ b/t/utils/llist_test.c
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