Skip to content

Commit

Permalink
Clean up clixon_rpc_err data at shutdown
Browse files Browse the repository at this point in the history
It might be left lying around at shutdown, make sure it's freed.

Also, it might be the case someday that an error will be generated when
the old error had not yet been read.  Make sure the data is freed
properly in case that ever happens.

Signed-off-by: Corey Minyard <[email protected]>
  • Loading branch information
cminyard committed Jan 28, 2025
1 parent a479094 commit d598866
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apps/backend/backend_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ backend_terminate(clixon_handle h)
/* Delete all plugins, RPC callbacks, and upgrade callbacks */
clixon_plugin_module_exit(h);
/* Delete all process-control entries */
clixon_process_delete_all(h);
clixon_process_delete_all(h);
/* Free memory associated with plugin_rpc_err() */
clixon_plugin_rpc_err_exit(h);

xpath_optimize_exit();
clixon_pagination_free(h);
Expand Down
1 change: 1 addition & 0 deletions lib/clixon/clixon_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ int clixon_plugin_module_exit(clixon_handle h);
int clixon_plugin_rpc_err(clixon_handle h, const char *ns,
const char *type, const char *tag, const char *info,
const char *severity, const char *fmt, ...);
void clixon_plugin_rpc_err_exit(clixon_handle h);
int clixon_plugin_rpc_err_set(clixon_handle h);
int clixon_plugin_report_err(clixon_handle h, cbuf *cbret);
int clixon_plugin_report_err_xml(clixon_handle h, cxobj **xreg, char *err, ...);
Expand Down
18 changes: 18 additions & 0 deletions lib/src/clixon_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,7 @@ clixon_plugin_rpc_err(clixon_handle h,
int retval = -1;
int err;
cvec *cvv = NULL;
cvec *old_cvv = clicon_data_cvec_get(h, "rpc_err");

cvv = cvec_new(0);
if (!cvv)
Expand Down Expand Up @@ -1838,10 +1839,27 @@ clixon_plugin_rpc_err(clixon_handle h,
done:
if (retval && cvv)
cvec_free(cvv);
if (!retval && old_cvv)
cvec_free(old_cvv);
return retval;
}

/*! Frees memory associated with clixon_rpc_err().
*
* @param[in] h Clixon
*/
void
clixon_plugin_rpc_err_exit(clixon_handle h)
{
cvec *cvv = clicon_data_cvec_get(h, "rpc_err");

clicon_ptr_del(h, "rpc_err");
cvec_free(cvv);
}

/*! Returns if the rpc error has already been set.
*
* @param[in] h Clixon
*
* @retval 0 The rpc error is not set
* @retval 1 The rpc error is set
Expand Down

0 comments on commit d598866

Please sign in to comment.