From 5ae2c1913595cbafa3caedebb556d45e123f6bcd Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 18 Apr 2014 14:50:11 +0200 Subject: [PATCH] plugin: Increment ref-count for a context stored in the TSD. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … 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. --- src/core/plugin.c | 5 +++++ 1 file changed, 5 insertions(+) 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 */ -- 2.30.2