libabc: Make things hold a reference to their context The sample libabc includes functions to get a "thing", as a sample sub-object of the overall library context. Each "thing" has a reference to the parent library context, and a function to return that reference. Given that, abc_thing_new_from_string should call abc_ref, and abc_thing_unref should call abc_unref when freeing a thing.
diff --git a/src/libabc.c b/src/libabc.c index d6ef0b4..21e434b 100644 --- a/src/libabc.c +++ b/src/libabc.c
@@ -251,6 +251,7 @@ if (thing->refcount > 0) return NULL; dbg(thing->ctx, "context %p released\n", thing); + abc_unref(thing->ctx); free(thing); return NULL; } @@ -269,7 +270,7 @@ return -ENOMEM; t->refcount = 1; - t->ctx = ctx; + t->ctx = abc_ref(ctx); *thing = t; return 0; }