From: Sebastian Harl Date: Fri, 18 Apr 2014 12:50:11 +0000 (+0200) Subject: plugin: Increment ref-count for a context stored in the TSD. X-Git-Tag: sysdb-0.1.0~119 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=5ae2c1913595cbafa3caedebb556d45e123f6bcd plugin: Increment ref-count for a context stored in the TSD. … and release it when removing it from the TSD. While this shouldn't matter when everything is done right, this ensures that memory management is done right. --- diff --git a/src/core/plugin.c b/src/core/plugin.c index 18ea82c..e67f814 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -299,6 +299,7 @@ ctx_create(const char *name) if (! plugin_ctx_key_initialized) ctx_key_init(); + sdb_object_ref(SDB_OBJ(ctx)); pthread_setspecific(plugin_ctx_key, ctx); return ctx; } /* ctx_create */ @@ -320,6 +321,10 @@ ctx_set(ctx_t *new) ctx_key_init(); old = pthread_getspecific(plugin_ctx_key); + if (old) + sdb_object_deref(SDB_OBJ(old)); + if (new) + sdb_object_ref(SDB_OBJ(new)); pthread_setspecific(plugin_ctx_key, new); return old; } /* ctx_set */