Release job message status to avoid memory leak (#15822)
Release reason if job not found
Stelios Fragkakis committed
Aug 17, 2023 at 00:14 UTC
18d71460d5deaec1a3ccaf637cdcb40c743d1bd7
1 file changed
+5
-1
libnetdata/dyn_conf/dyn_conf.c
+5
-1
@@ -820,9 +820,11 @@ void plugin_del_cb(const DICTIONARY_ITEM *item, void *value, void *data)
820
821
void report_job_status(struct configurable_plugin *plugin, const char *module_name, const char *job_name, enum job_status status, int status_code, char *reason)
822
{
823
+ struct job *job = NULL;
824
const DICTIONARY_ITEM *item = dictionary_get_and_acquire_item(plugins_dict, plugin->name);
825
if (item == NULL) {
826
netdata_log_error("plugin %s not found", plugin->name);
827
+ freez(reason);
828
return;
829
}
830
struct configurable_plugin *plug = dictionary_acquired_item_value(item);
@@ -840,7 +842,7 @@ void report_job_status(struct configurable_plugin *plugin, const char *module_na
842
netdata_log_error("job %s not found", job_name);
843
goto EXIT_PLUGIN;
844
}
843
- struct job *job = dictionary_acquired_item_value(job_item);
845
+ job = dictionary_acquired_item_value(job_item);
846
job->status = status;
847
job->state = status_code;
848
if (job->reason != NULL) {
@@ -852,6 +854,8 @@ void report_job_status(struct configurable_plugin *plugin, const char *module_na
854
dictionary_acquired_item_release(mod->jobs, job_item);
855
856
EXIT_PLUGIN:
857
+ if (!job)
858
+ freez(reason);
859
dictionary_acquired_item_release(plugins_dict, item);
860
}
861