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.
---
 src/libabc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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 @@ ABC_EXPORT struct abc_thing *abc_thing_unref(struct 
abc_thing *thing)
         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 @@ ABC_EXPORT int abc_thing_new_from_string(struct abc_ctx 
*ctx, const char *string
                 return -ENOMEM;
 
         t->refcount = 1;
-        t->ctx = ctx;
+        t->ctx = abc_ref(ctx);
         *thing = t;
         return 0;
 }
-- 
2.1.3

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to