From: Sebastian Harl Date: Sun, 20 Apr 2014 10:05:57 +0000 (+0200) Subject: plugin: Let ctx_create() use ctx_set(). X-Git-Tag: sysdb-0.1.0~115 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a9f99c057f72b31de1fa718cd6abe1ea5005ee28;p=sysdb.git plugin: Let ctx_create() use ctx_set(). This ensures consistent handling of reference counts. --- diff --git a/src/core/plugin.c b/src/core/plugin.c index 929abae..7584aa5 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -292,22 +292,6 @@ static sdb_type_t ctx_type = { ctx_destroy }; -static ctx_t * -ctx_create(const char *name) -{ - ctx_t *ctx; - - ctx = CTX(sdb_object_create(name, ctx_type)); - if (! ctx) - return NULL; - - if (! plugin_ctx_key_initialized) - ctx_key_init(); - sdb_object_ref(SDB_OBJ(ctx)); - pthread_setspecific(plugin_ctx_key, ctx); - return ctx; -} /* ctx_create */ - static ctx_t * ctx_get(void) { @@ -333,6 +317,21 @@ ctx_set(ctx_t *new) return old; } /* ctx_set */ +static ctx_t * +ctx_create(const char *name) +{ + ctx_t *ctx; + + ctx = CTX(sdb_object_create(name, ctx_type)); + if (! ctx) + return NULL; + + if (! plugin_ctx_key_initialized) + ctx_key_init(); + ctx_set(ctx); + return ctx; +} /* ctx_create */ + static int plugin_cb_init(sdb_object_t *obj, va_list ap) {