From 551a36e43b6831abff85a068780a397491f504a1 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 6 Jun 2018 16:03:00 +0000 Subject: [PATCH] Fix: Added handling of newcb and freecb --- src/module.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/module.c b/src/module.c index 8aa82820..1e68b4ef 100644 --- a/src/module.c +++ b/src/module.c @@ -10,6 +10,7 @@ #include #endif +#include #include #include "common/thread/thread.h" @@ -23,6 +24,8 @@ struct module_tag { mutex_t lock; const module_client_handler_t *client_handlers; size_t client_handlers_len; + module_setup_handler_t freecb; + void *userdata; }; @@ -116,6 +119,13 @@ module_t * module_container_get_module(module_container_t *self, co static void __module_free(refobject_t self, void **userdata) { module_t *mod = REFOBJECT_TO_TYPE(self, module_t *); + + if (mod->freecb) + mod->freecb(mod, &(mod->userdata)); + + if (mod->userdata) + free(mod->userdata); + thread_mutex_destroy(&(mod->lock)); } @@ -128,6 +138,16 @@ module_t * module_new(const char *name, module_setup_handler_t newc thread_mutex_create(&(ret->lock)); + ret->userdata = userdata; + ret->freecb = freecb; + + if (newcb) { + if (newcb(ret, &(ret->userdata)) != 0) { + refobject_unref(ret); + return NULL; + } + } + return ret; }