Code

plugin: Increment ref-count for a context stored in the TSD.
authorSebastian Harl <sh@tokkee.org>
Fri, 18 Apr 2014 12:50:11 +0000 (14:50 +0200)
committerSebastian Harl <sh@tokkee.org>
Fri, 18 Apr 2014 12:50:11 +0000 (14:50 +0200)
… 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

index 18ea82c77fc8475d73dfb9e4a37b8a7a693443fc..e67f814ba24510ae47b2640bddfa17dacea3c76f 100644 (file)
@@ -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 */