Code

object: Assert that object's are not free'd multiple times.
authorSebastian Harl <sh@tokkee.org>
Sun, 5 Oct 2014 16:09:00 +0000 (18:09 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 5 Oct 2014 17:19:03 +0000 (19:19 +0200)
Else, we'd access free'd memory when trying to do so.

src/core/object.c
t/unit/core/object_test.c

index 9101918654379a1ff41491df64187d399468d186..c39faf4aed2c89f684a3e2c0c947b0eba7fe2d18 100644 (file)
@@ -149,6 +149,9 @@ sdb_object_deref(sdb_object_t *obj)
        if (obj->ref_cnt > 0)
                return;
 
+       /* we'd access free'd memory in case ref_cnt < 0 */
+       assert(! obj->ref_cnt);
+
        if (obj->type.destroy)
                obj->type.destroy(obj);
 
index dec6d41c73a3f989e97fcd85c79e4a950908ab79..73d7c86e1f1b21c18de0746ec250132df1001706 100644 (file)
@@ -275,8 +275,7 @@ START_TEST(test_obj_ref)
                        "%d time%s; expected: 0", destroy_noop_called == 1 ? "" : "2",
                        destroy_noop_called);
 
-       /* test_obj_create already checks the ref_cnt == 1 case */
-       obj->ref_cnt = 0;
+       obj->ref_cnt = 1;
        sdb_object_deref(obj);
        fail_unless(init_noop_called == 1,
                        "after some sdb_object_{de,}ref(); object's init called %d times; "