status = -1;
}
- if (status == 0) {
- char callback_name[3 * DATA_MAX_NAME_LEN];
-
- snprintf(callback_name, sizeof(callback_name), "apache/%s/%s",
- (st->host != NULL) ? st->host : hostname_g,
- (st->name != NULL) ? st->name : "default");
-
- status = plugin_register_complex_read(
- /* group = */ NULL,
- /* name = */ callback_name,
- /* callback = */ apache_read_host,
- /* interval = */ 0,
- &(user_data_t){
- .data = st, .free_func = apache_free,
- });
- }
-
if (status != 0) {
apache_free(st);
return -1;
}
- return 0;
+ char callback_name[3 * DATA_MAX_NAME_LEN];
+
+ snprintf(callback_name, sizeof(callback_name), "apache/%s/%s",
+ (st->host != NULL) ? st->host : hostname_g,
+ (st->name != NULL) ? st->name : "default");
+
+ return plugin_register_complex_read(
+ /* group = */ NULL,
+ /* name = */ callback_name,
+ /* callback = */ apache_read_host,
+ /* interval = */ 0,
+ &(user_data_t){
+ .data = st, .free_func = apache_free,
+ });
} /* int config_add */
static int config(oconfig_item_t *ci) {
return 0;
} /* }}} int plugin_update_internal_statistics */
-static void destroy_callback(callback_func_t *cf) /* {{{ */
+static void free_userdata(user_data_t const *ud) /* {{{ */
{
- if (cf == NULL)
+ if (ud == NULL)
return;
- if ((cf->cf_udata.data != NULL) && (cf->cf_udata.free_func != NULL)) {
- cf->cf_udata.free_func(cf->cf_udata.data);
- cf->cf_udata.data = NULL;
- cf->cf_udata.free_func = NULL;
+ if ((ud->data != NULL) && (ud->free_func != NULL)) {
+ ud->free_func(ud->data);
}
+} /* }}} void free_userdata */
+
+static void destroy_callback(callback_func_t *cf) /* {{{ */
+{
+ if (cf == NULL)
+ return;
+ free_userdata(&cf->cf_udata);
sfree(cf);
} /* }}} void destroy_callback */
cf = calloc(1, sizeof(*cf));
if (cf == NULL) {
+ free_userdata(ud);
ERROR("plugin: create_register_callback: calloc failed.");
return -1;
}
rf = calloc(1, sizeof(*rf));
if (rf == NULL) {
+ free_userdata(user_data);
ERROR("plugin_register_complex_read: calloc failed.");
return ENOMEM;
}
status = plugin_insert_read(rf);
if (status != 0) {
+ free_userdata(&rf->rf_udata);
sfree(rf->rf_name);
sfree(rf);
}
});
sfree(flush_name);
- if (status != 0) {
- sfree(cb->name);
- sfree(cb);
- return status;
- }
+ return status;
}
return 0;
return 0;
} /* int memcached_read */
-static int memcached_add_read_callback(memcached_t *st) {
- char callback_name[3 * DATA_MAX_NAME_LEN];
- int status;
-
- snprintf(callback_name, sizeof(callback_name), "memcached/%s",
- (st->name != NULL) ? st->name : "__legacy__");
-
+static int memcached_set_defaults(memcached_t *st) {
/* If no <Address> used then:
* - Connect to the destination specified by <Host>, if present.
* If not, use the default address.
assert(st->connhost != NULL);
assert(st->connport != NULL);
- status = plugin_register_complex_read(
+ return 0;
+} /* int memcached_set_defaults */
+
+static int memcached_add_read_callback(memcached_t *st) {
+ char callback_name[3 * DATA_MAX_NAME_LEN];
+
+ if (memcached_set_defaults(st) != 0) {
+ memcached_free(st);
+ return -1;
+ }
+
+ snprintf(callback_name, sizeof(callback_name), "memcached/%s",
+ (st->name != NULL) ? st->name : "__legacy__");
+
+ return plugin_register_complex_read(
/* group = */ "memcached",
/* name = */ callback_name,
/* callback = */ memcached_read,
&(user_data_t){
.data = st, .free_func = memcached_free,
});
-
- return status;
} /* int memcached_add_read_callback */
/* Configuration handling functiions
break;
}
- if (status == 0)
- status = memcached_add_read_callback(st);
-
if (status != 0) {
memcached_free(st);
return -1;
}
- return 0;
-}
+ return memcached_add_read_callback(st);
+} /* int config_add_instance */
static int memcached_config(oconfig_item_t *ci) {
- int status = 0;
_Bool have_instance_block = 0;
for (int i = 0; i < ci->children_num; i++) {
child->key);
} /* for (ci->children) */
- return status;
-}
+ return 0;
+} /* int memcached_config */
static int memcached_init(void) {
memcached_t *st;
status = memcached_add_read_callback(st);
if (status == 0)
memcached_have_instances = 1;
- else
- memcached_free(st);
return status;
} /* int memcached_init */
ret = plugin_register_flush("perl", perl_flush, /* user_data = */ NULL);
}
- if (0 == ret)
+ if (0 == ret) {
ret = plugin_register_flush(pluginname, perl_flush, &userdata);
+ } else {
+ free(userdata.data);
+ }
} else {
ret = -1;
}
if (0 == ret)
XSRETURN_YES;
- else {
- free(userdata.data);
+ else
XSRETURN_EMPTY;
- }
} /* static void _plugin_register_generic_userdata ( ... ) */
/*
}
}
- snprintf(read_name, sizeof(read_name), "routeros/%s", router_data->node);
- if (status == 0)
- status = plugin_register_complex_read(
- /* group = */ NULL, read_name, cr_read, /* interval = */ 0,
- &(user_data_t){
- .data = router_data, .free_func = (void *)cr_free_data,
- });
-
- if (status != 0)
+ if (status != 0) {
cr_free_data(router_data);
+ return status;
+ }
- return status;
+ snprintf(read_name, sizeof(read_name), "routeros/%s", router_data->node);
+ return plugin_register_complex_read(
+ /* group = */ NULL, read_name, cr_read, /* interval = */ 0,
+ &(user_data_t){
+ .data = router_data, .free_func = (void *)cr_free_data,
+ });
} /* }}} int cr_config_router */
static int cr_config(oconfig_item_t *ci) {
});
if (status != 0) {
ERROR("snmp plugin: Registering complex read function failed.");
- csnmp_host_definition_destroy(hd);
return -1;
}
});
if (status != 0) {
ERROR("tail_csv plugin: Registering complex read function failed.");
- tcsv_instance_definition_destroy(id);
return -1;
}