summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ac23a82)
raw | patch | inline | side by side (parent: ac23a82)
author | Florian Forster <octo@huhu.verplant.org> | |
Tue, 11 Jan 2011 08:06:58 +0000 (09:06 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Tue, 11 Jan 2011 08:06:58 +0000 (09:06 +0100) |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index eb98a7a33a3944ccf5851147e6e96f702c0d1b62..9ecee5cf26f5fd1b2d421d0d69a3f6476a0815b0 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
int (*callback) (void))
{
read_func_t *rf;
+ int status;
- rf = (read_func_t *) malloc (sizeof (read_func_t));
+ rf = malloc (sizeof (*rf));
if (rf == NULL)
{
- char errbuf[1024];
- ERROR ("plugin_register_read: malloc failed: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- return (-1);
+ ERROR ("plugin_register_read: malloc failed.");
+ return (ENOMEM);
}
memset (rf, 0, sizeof (read_func_t));
rf->rf_interval.tv_nsec = 0;
rf->rf_effective_interval = rf->rf_interval;
- return (plugin_insert_read (rf));
+ status = plugin_insert_read (rf);
+ if (status != 0)
+ sfree (rf);
+
+ return (status);
} /* int plugin_register_read */
int plugin_register_complex_read (const char *group, const char *name,
user_data_t *user_data)
{
read_func_t *rf;
+ int status;
- rf = (read_func_t *) malloc (sizeof (read_func_t));
+ rf = malloc (sizeof (*rf));
if (rf == NULL)
{
ERROR ("plugin_register_complex_read: malloc failed.");
- return (-1);
+ return (ENOMEM);
}
memset (rf, 0, sizeof (read_func_t));
rf->rf_udata = *user_data;
}
- return (plugin_insert_read (rf));
+ status = plugin_insert_read (rf);
+ if (status != 0)
+ sfree (rf);
+
+ return (status);
} /* int plugin_register_complex_read */
int plugin_register_write (const char *name,
diff --git a/src/plugin.h b/src/plugin.h
index 937eebed4e1cb24da6e18d3971566cbe3a8c18ff..4d5201b68d3bd0b532630a0cef3ed211c72a2fed 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
plugin_init_cb callback);
int plugin_register_read (const char *name,
int (*callback) (void));
+/* "user_data" will be freed automatically, unless
+ * "plugin_register_complex_read" returns an error (non-zero). */
int plugin_register_complex_read (const char *group, const char *name,
plugin_read_cb callback,
const struct timespec *interval,