diff --git a/apps/backend/backend_commit.c b/apps/backend/backend_commit.c index e5a141c7..0f71b19e 100644 --- a/apps/backend/backend_commit.c +++ b/apps/backend/backend_commit.c @@ -931,21 +931,20 @@ from_client_restart_one(clicon_handle h, yang_stmt *yspec; int i; cxobj *xn; + plugin_context_t *pc = NULL; yspec = clicon_dbspec_yang(h); if (xmldb_db_reset(h, db) < 0) goto done; /* Application may define extra xml in its reset function*/ if ((resetfn = clixon_plugin_api_get(cp)->ca_reset) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if ((retval = resetfn(h, db)) < 0) { clicon_debug(1, "plugin_start() failed"); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } /* 1. Start transaction */ @@ -1027,6 +1026,8 @@ from_client_restart_one(clicon_handle h, goto fail; retval = 1; done: + if (pc) + free(pc); if (td){ xmldb_get0_free(h, &td->td_target); transaction_free(td); diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index 0d4565b7..6d1c1daf 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -78,13 +78,12 @@ clixon_plugin_reset_one(clixon_plugin_t *cp, clicon_handle h, char *db) { - int retval = -1; - plgreset_t *fn; /* callback */ + int retval = -1; + plgreset_t *fn; /* callback */ + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_reset) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, db) < 0) { if (clicon_errno < 0) @@ -92,11 +91,13 @@ clixon_plugin_reset_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -137,12 +138,12 @@ clixon_plugin_pre_daemon_one(clixon_plugin_t *cp, { int retval = -1; plgdaemon_t *fn; /* Daemonize plugin callback function */ + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_pre_daemon) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; + if (fn(h) < 0) { if (clicon_errno < 0) clicon_log(LOG_WARNING, "%s: Internal error: Pre-daemon callback in plugin:\ @@ -150,11 +151,13 @@ clixon_plugin_pre_daemon_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -196,11 +199,10 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp, { int retval = -1; plgdaemon_t *fn; /* Daemonize plugin callback function */ + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_daemon) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h) < 0) { if (clicon_errno < 0) @@ -208,11 +210,13 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -279,13 +283,12 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp, int retval = -1; plgstatedata_t *fn; /* Plugin statedata fn */ cxobj *x = NULL; + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_statedata) != NULL){ if ((x = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL) goto done; - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, nsc, xpath, x) < 0){ if (clicon_errno < 0) @@ -293,13 +296,15 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto fail; /* Dont quit here on user callbacks */ } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } if (xp && x) *xp = x; retval = 1; done: + if (pc) + free(pc); return retval; fail: retval = 0; @@ -432,19 +437,20 @@ clixon_plugin_lockdb_one(clixon_plugin_t *cp, { int retval = -1; plglockdb_t *fn; /* Plugin statedata fn */ + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_lockdb) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, db, lock, id) < 0) goto done; - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -607,11 +613,10 @@ plugin_transaction_begin_one(clixon_plugin_t *cp, { int retval = -1; trans_cb_t *fn; + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_trans_begin) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, (transaction_data)td) < 0){ if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ @@ -619,11 +624,13 @@ plugin_transaction_begin_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -666,11 +673,10 @@ plugin_transaction_validate_one(clixon_plugin_t *cp, { int retval = -1; trans_cb_t *fn; - - if ((fn = clixon_plugin_api_get(cp)->ca_trans_validate) != NULL){ - plugin_context_t pc = {0,}; + plugin_context_t *pc = NULL; - if (plugin_context_get(&pc) < 0) + if ((fn = clixon_plugin_api_get(cp)->ca_trans_validate) != NULL){ + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, (transaction_data)td) < 0){ if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ @@ -678,11 +684,13 @@ plugin_transaction_validate_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -723,11 +731,10 @@ plugin_transaction_complete_one(clixon_plugin_t *cp, { int retval = -1; trans_cb_t *fn; + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_trans_complete) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, (transaction_data)td) < 0){ if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ @@ -735,11 +742,13 @@ plugin_transaction_complete_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -812,11 +821,10 @@ plugin_transaction_commit_one(clixon_plugin_t *cp, { int retval = -1; trans_cb_t *fn; + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_trans_commit) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, (transaction_data)td) < 0){ if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ @@ -824,11 +832,13 @@ plugin_transaction_commit_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -877,11 +887,10 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp, { int retval = -1; trans_cb_t *fn; + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_trans_commit_done) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, (transaction_data)td) < 0){ if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ @@ -889,11 +898,13 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -934,11 +945,10 @@ plugin_transaction_end_one(clixon_plugin_t *cp, { int retval = -1; trans_cb_t *fn; + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_trans_end) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, (transaction_data)td) < 0){ if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ @@ -946,11 +956,13 @@ plugin_transaction_end_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -984,11 +996,10 @@ plugin_transaction_abort_one(clixon_plugin_t *cp, { int retval = -1; trans_cb_t *fn; + plugin_context_t *pc = NULL; if ((fn = clixon_plugin_api_get(cp)->ca_trans_abort) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, (transaction_data)td) < 0){ if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ @@ -996,11 +1007,13 @@ plugin_transaction_abort_one(clixon_plugin_t *cp, __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } - if (plugin_context_check(&pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) + if (plugin_context_check(pc, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } diff --git a/apps/cli/cli_plugin.c b/apps/cli/cli_plugin.c index 34c1888b..cf52bd7b 100644 --- a/apps/cli/cli_plugin.c +++ b/apps/cli/cli_plugin.c @@ -533,16 +533,16 @@ cligen_clixon_eval(cligen_handle h, struct cg_callback *cc; int retval = 0; cvec *argv; + plugin_context_t *pc = NULL; if (h) cligen_co_match_set(h, co); for (cc = co->co_callbacks; cc; cc=cc->cc_next){ /* Vector cvec argument to callback */ if (cc->cc_fn_vec){ - plugin_context_t pc = {0,}; argv = cc->cc_cvec ? cvec_dup(cc->cc_cvec) : NULL; cligen_fn_str_set(h, cc->cc_fn_str); - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) break; if ((retval = (*cc->cc_fn_vec)( cligen_userhandle(h)?cligen_userhandle(h):h, @@ -553,13 +553,19 @@ cligen_clixon_eval(cligen_handle h, cligen_fn_str_set(h, NULL); break; } - if (plugin_context_check(&pc, "CLIgen", cc->cc_fn_str) < 0) + if (plugin_context_check(pc, "CLIgen", cc->cc_fn_str) < 0) break; + if (pc){ + free(pc); + pc = NULL; + } if (argv != NULL) cvec_free(argv); cligen_fn_str_set(h, NULL); } } + if (pc) + free(pc); return retval; } diff --git a/lib/clixon/clixon_plugin.h b/lib/clixon/clixon_plugin.h index e487b035..c7294881 100644 --- a/lib/clixon/clixon_plugin.h +++ b/lib/clixon/clixon_plugin.h @@ -337,16 +337,6 @@ struct clixon_plugin_api{ #define ca_trans_abort u.cau_backend.cb_trans_abort #define ca_datastore_upgrade u.cau_backend.cb_datastore_upgrade -/*! Structure for checking status before and after a plugin call - * Currently signal settings: blocked and handlers, could be extended to more - * @see plugin_context_check - */ -struct plugin_context { - sigset_t pc_sigset; /* See sigprocmask(2) */ - struct sigaction pc_sigaction_vec[32]; /* See sigaction(2) */ - int pc_status; /* 0: OK, -1: fail */ -}; -typedef struct plugin_context plugin_context_t; /* * Macros @@ -359,6 +349,10 @@ typedef struct clixon_plugin_api clixon_plugin_api; * The internal struct is defined in clixon_plugin.c */ typedef struct clixon_plugin clixon_plugin_t; +/*! Structure for checking status before and after a plugin call + * The internal struct is defined in clixon_plugin.c */ +typedef struct plugin_context plugin_context_t; + /* * Prototypes */ @@ -371,7 +365,6 @@ typedef struct clixon_plugin clixon_plugin_t; */ clixon_plugin_api *clixon_plugin_init(clicon_handle h); - clixon_plugin_api *clixon_plugin_api_get(clixon_plugin_t *cp); char *clixon_plugin_name_get(clixon_plugin_t *cp); plghndl_t clixon_plugin_handle_get(clixon_plugin_t *cp); @@ -386,7 +379,7 @@ int clixon_plugins_load(clicon_handle h, const char *function, const char *dir, int clixon_pseudo_plugin(clicon_handle h, const char *name, clixon_plugin_t **cpp); -int plugin_context_get(plugin_context_t *pc); +plugin_context_t * plugin_context_get(void); int plugin_context_check(plugin_context_t *pc, const char *name, const char *fn); int clixon_plugin_start_one(clixon_plugin_t *cp, clicon_handle h); diff --git a/lib/src/clixon_plugin.c b/lib/src/clixon_plugin.c index 9a804cdd..d55c8cb8 100644 --- a/lib/src/clixon_plugin.c +++ b/lib/src/clixon_plugin.c @@ -70,6 +70,15 @@ /* * Private types */ +/*! Structure for checking status before and after a plugin call + * Currently signal settings: blocked and handlers, could be extended to more + * @see plugin_context_check + */ +struct plugin_context { + sigset_t pc_sigset; /* See sigprocmask(2) */ + struct sigaction pc_sigaction_vec[32]; /* See sigaction(2) */ + int pc_status; /* 0: OK, -1: fail */ +}; /* Internal plugin structure with dlopen() handle and plugin_api * This is an internal type, not exposed in the API @@ -328,10 +337,10 @@ plugin_load_one(clicon_handle h, void *handle = NULL; plginit2_t *initfn; clixon_plugin_api *api = NULL; - clixon_plugin_t *cp = NULL; + clixon_plugin_t *cp = NULL; char *name; char *p; - plugin_context_t pc = {0,}; + plugin_context_t *pc = NULL; clicon_debug(1, "%s file:%s function:%s", __FUNCTION__, file, function); dlerror(); /* Clear any existing error */ @@ -350,9 +359,7 @@ plugin_load_one(clicon_handle h, goto done; } clicon_err_reset(); - - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) < 0) goto done; if ((api = initfn(h)) == NULL) { @@ -366,7 +373,7 @@ plugin_load_one(clicon_handle h, goto done; } } - if (plugin_context_check(&pc, file, __FUNCTION__) < 0) + if (plugin_context_check(pc, file, __FUNCTION__) < 0) goto done; /* Note: sizeof clixon_plugin_api which is largest of clixon_plugin_api:s */ @@ -392,6 +399,8 @@ plugin_load_one(clicon_handle h, retval = 1; done: clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); + if (pc) + free(pc); if (retval != 1 && handle) dlclose(handle); if (cp) @@ -495,14 +504,20 @@ done: /*! Get system context, eg signal procmask (for blocking) and sigactions * Call this before a plugin + * @retval pc Plugin context structure, use free() to deallocate + * @retval NULL Error * @see plugin_context_check - */ -int -plugin_context_get(plugin_context_t *pc) + * */ +plugin_context_t * +plugin_context_get(void) { - int retval = -1; - int i; + int i; + struct plugin_context *pc = NULL; + if ((pc = malloc(sizeof *pc)) == NULL){ + clicon_err(OE_UNIX, errno, "malloc"); + goto done; + } if (sigprocmask(0, NULL, &pc->pc_sigset) < 0){ clicon_err(OE_UNIX, errno, "sigprocmask"); goto done; @@ -521,9 +536,11 @@ plugin_context_get(plugin_context_t *pc) pc->pc_sigaction_vec[i].sa_flags &= ~0x04000000; #endif } - retval = 0; + return pc; done: - return retval; + if (pc) + free(pc); + return NULL; } /*! Given an existing, old plugin context, check if anytjing has changed @@ -535,39 +552,40 @@ plugin_context_get(plugin_context_t *pc) * @see plugin_context_get */ int -plugin_context_check(plugin_context_t *oldpc, +plugin_context_check(plugin_context_t *oldpc0, const char *name, const char *fn) { - int retval = -1; - int failed; - int i; - plugin_context_t newpc = {0, }; + int retval = -1; + int failed; + int i; + struct plugin_context *oldpc = oldpc0; + struct plugin_context *newpc = NULL; - if (plugin_context_get(&newpc) < 0) + if ((newpc = plugin_context_get()) == NULL) goto done; for (i=1; i<32; i++){ failed = 0; - if (sigismember(&oldpc->pc_sigset, i) != sigismember(&newpc.pc_sigset, i)){ + if (sigismember(&oldpc->pc_sigset, i) != sigismember(&newpc->pc_sigset, i)){ clicon_log(LOG_WARNING, "%s Plugin %s %s: Changed blocking of signal %s(%d) from %d to %d", __FUNCTION__, name, fn, strsignal(i), i, sigismember(&oldpc->pc_sigset, i), - sigismember(&newpc.pc_sigset, i) + sigismember(&newpc->pc_sigset, i) ); failed++; } - if (oldpc->pc_sigaction_vec[i].sa_flags != newpc.pc_sigaction_vec[i].sa_flags){ + if (oldpc->pc_sigaction_vec[i].sa_flags != newpc->pc_sigaction_vec[i].sa_flags){ clicon_log(LOG_WARNING, "%s Plugin %s %s: Changed flags of signal %s(%d) from 0x%x to 0x%x", __FUNCTION__, name, fn, strsignal(i), i, oldpc->pc_sigaction_vec[i].sa_flags, - newpc.pc_sigaction_vec[i].sa_flags);; + newpc->pc_sigaction_vec[i].sa_flags);; failed++; } - if (oldpc->pc_sigaction_vec[i].sa_sigaction != newpc.pc_sigaction_vec[i].sa_sigaction){ + if (oldpc->pc_sigaction_vec[i].sa_sigaction != newpc->pc_sigaction_vec[i].sa_sigaction){ clicon_log(LOG_WARNING, "%s Plugin %s %s: Changed action of signal %s(%d) from %p to %p", __FUNCTION__, name, fn, strsignal(i), i, oldpc->pc_sigaction_vec[i].sa_sigaction, - newpc.pc_sigaction_vec[i].sa_sigaction); + newpc->pc_sigaction_vec[i].sa_sigaction); failed++; } if (failed){ @@ -577,6 +595,8 @@ plugin_context_check(plugin_context_t *oldpc, } retval = 0; done: + if (newpc) + free(newpc); return retval; } @@ -590,13 +610,12 @@ int clixon_plugin_start_one(clixon_plugin_t *cp, clicon_handle h) { - int retval = -1; - plgstart_t *fn; /* Plugin start */ + int retval = -1; + plgstart_t *fn; /* Plugin start */ + plugin_context_t *pc = NULL; if ((fn = cp->cp_api.ca_start) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h) < 0) { if (clicon_errno < 0) @@ -604,11 +623,13 @@ clixon_plugin_start_one(clixon_plugin_t *cp, __FUNCTION__, cp->cp_name); goto done; } - if (plugin_context_check(&pc, cp->cp_name, __FUNCTION__) < 0) + if (plugin_context_check(pc, cp->cp_name, __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -643,14 +664,13 @@ static int clixon_plugin_exit_one(clixon_plugin_t *cp, clicon_handle h) { - int retval = -1; - char *error; - plgexit_t *fn; - + int retval = -1; + char *error; + plgexit_t *fn; + plugin_context_t *pc = NULL; + if ((fn = cp->cp_api.ca_exit) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h) < 0) { if (clicon_errno < 0) @@ -658,7 +678,7 @@ clixon_plugin_exit_one(clixon_plugin_t *cp, __FUNCTION__, cp->cp_name); goto done; } - if (plugin_context_check(&pc, cp->cp_name, __FUNCTION__) < 0) + if (plugin_context_check(pc, cp->cp_name, __FUNCTION__) < 0) goto done; if (dlclose(cp->cp_handle) != 0) { error = (char*)dlerror(); @@ -667,6 +687,8 @@ clixon_plugin_exit_one(clixon_plugin_t *cp, } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -715,14 +737,13 @@ clixon_plugin_auth_one(clixon_plugin_t *cp, clixon_auth_type_t auth_type, char **authp) { - int retval = -1; - plgauth_t *fn; /* Plugin auth */ + int retval = -1; + plgauth_t *fn; /* Plugin auth */ + plugin_context_t *pc = NULL; clicon_debug(1, "%s", __FUNCTION__); if ((fn = cp->cp_api.ca_auth) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if ((retval = fn(h, req, auth_type, authp)) < 0) { if (clicon_errno < 0) @@ -730,12 +751,14 @@ clixon_plugin_auth_one(clixon_plugin_t *cp, __FUNCTION__, cp->cp_name); goto done; } - if (plugin_context_check(&pc, cp->cp_name, __FUNCTION__) < 0) + if (plugin_context_check(pc, cp->cp_name, __FUNCTION__) < 0) goto done; } else retval = 0; /* Ignored / no callback */ done: + if (pc) + free(pc); clicon_debug(1, "%s retval:%d auth:%s", __FUNCTION__, retval, *authp); return retval; } @@ -799,13 +822,12 @@ clixon_plugin_extension_one(clixon_plugin_t *cp, yang_stmt *yext, yang_stmt *ys) { - int retval = 1; - plgextension_t *fn; /* Plugin extension fn */ + int retval = 1; + plgextension_t *fn; /* Plugin extension fn */ + plugin_context_t *pc = NULL; if ((fn = cp->cp_api.ca_extension) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, yext, ys) < 0) { if (clicon_errno < 0) @@ -813,11 +835,13 @@ clixon_plugin_extension_one(clixon_plugin_t *cp, __FUNCTION__, cp->cp_name); goto done; } - if (plugin_context_check(&pc, cp->cp_name, __FUNCTION__) < 0) + if (plugin_context_check(pc, cp->cp_name, __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; } @@ -871,11 +895,10 @@ clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp, { int retval = -1; datastore_upgrade_t *fn; + plugin_context_t *pc = NULL; if ((fn = cp->cp_api.ca_datastore_upgrade) != NULL){ - plugin_context_t pc = {0,}; - - if (plugin_context_get(&pc) < 0) + if ((pc = plugin_context_get()) == NULL) goto done; if (fn(h, db, xt, msd) < 0) { if (clicon_errno < 0) @@ -883,11 +906,13 @@ clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp, __FUNCTION__, cp->cp_name); goto done; } - if (plugin_context_check(&pc, cp->cp_name, __FUNCTION__) < 0) + if (plugin_context_check(pc, cp->cp_name, __FUNCTION__) < 0) goto done; } retval = 0; done: + if (pc) + free(pc); return retval; }