From a4b35de73384d4394b5201838c1c785355d9a7fd Mon Sep 17 00:00:00 2001 From: Yannick Gicquel Date: Thu, 28 Jan 2016 16:29:31 +0100 Subject: rest-api: fixup AFB_plugins allocated references plugins handles pointer to AFB_plugin structures which are located in each dynamically loaded plugin. Signed-off-by: Yannick Gicquel --- src/rest-api.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/rest-api.c b/src/rest-api.c index b0d7af00..e1c3756c 100644 --- a/src/rest-api.c +++ b/src/rest-api.c @@ -636,8 +636,7 @@ STATIC void scanDirectory(char *dirpath, int dirfd, AFB_plugin **plugins, int *c } if (verbose) fprintf(stderr, "[%s] is a valid AFB plugin, loading pos[%d]\n", pluginDir.d_name, *count); - plugins[*count] = (AFB_plugin *) malloc (sizeof(AFB_plugin)); - plugins[*count] = (**pluginRegisterFct)(); + plugins[*count] = pluginRegisterFct(); *count = *count +1; } @@ -646,7 +645,7 @@ STATIC void scanDirectory(char *dirpath, int dirfd, AFB_plugin **plugins, int *c } void initPlugins(AFB_session *session) { - static AFB_plugin **plugins; + AFB_plugin **plugins; afbJsonType = json_object_new_string (AFB_MSG_JTYPE); int count = 0; @@ -654,7 +653,7 @@ void initPlugins(AFB_session *session) { int dirfd; /* pre-allocate for AFB_MAX_PLUGINS plugins, we will downsize later */ - plugins = (AFB_plugin **) malloc (AFB_MAX_PLUGINS *sizeof(AFB_plugin)); + plugins = (AFB_plugin **) malloc (AFB_MAX_PLUGINS *sizeof(AFB_plugin*)); // Loop on every directory passed in --plugins=xxx while (dirpath = strsep(&session->config->ldpaths, ":")) { @@ -673,7 +672,7 @@ void initPlugins(AFB_session *session) { } // downsize structure to effective number of loaded plugins - plugins = (AFB_plugin **)realloc (plugins, (count+1)*sizeof(AFB_plugin)); + plugins = (AFB_plugin **)realloc (plugins, (count+1)*sizeof(AFB_plugin*)); plugins[count] = NULL; // complete plugins and save them within current sessions -- cgit 1.2.3-korg