aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2014-12-08 13:12:12 -0800
committerKay Sievers <kay@vrfy.org>2015-02-03 23:09:21 +0100
commitfe8daad4c8e0b58bbcd9168039c277399636448d (patch)
tree34488079ede5b8192decac6e48ed0db2412df4b6
parent3ee73a878ae076016bc93216e9989cec735e96f3 (diff)
downloadlibabc-fe8daad4c8e0b58bbcd9168039c277399636448d.tar.gz
libabc: Make things hold a reference to their contextHEADmaster
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.
-rw-r--r--src/libabc.c3
1 files changed, 2 insertions, 1 deletions
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;
}