summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 53651df)
raw | patch | inline | side by side (parent: 53651df)
author | Florian Forster <octo@huhu.verplant.org> | |
Fri, 4 May 2007 07:24:07 +0000 (09:24 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Fri, 4 May 2007 07:24:07 +0000 (09:24 +0200) |
Thus memory management is done by `plugin.c' and overwritten DSes can be freed.
src/plugin.c | patch | blob | history | |
src/types_list.c | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index 495e1693b91827bd9f50fc6adf5b5ad15367b308..ee1240cb575858ea9786bdcd39f76bdc921f2861 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
int plugin_register_data_set (const data_set_t *ds)
{
- return (register_callback (&list_data_set, ds->type, (void *) ds));
+ data_set_t *ds_copy;
+ int i;
+
+ if (llist_search (list_data_set, ds->type) != NULL)
+ {
+ NOTICE ("Replacing DS `%s' with another version.", ds->type);
+ plugin_unregister_data_set (ds->type);
+ }
+
+ ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
+ if (ds_copy == NULL)
+ return (-1);
+ memcpy(ds_copy, ds, sizeof (data_set_t));
+
+ ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
+ * ds->ds_num);
+ if (ds_copy->ds == NULL)
+ {
+ free (ds_copy);
+ return (-1);
+ }
+
+ for (i = 0; i < ds->ds_num; i++)
+ memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
+
+ return (register_callback (&list_data_set, ds->type, (void *) ds_copy));
} /* int plugin_register_data_set */
int plugin_register_log (char *name,
int plugin_unregister_data_set (const char *name)
{
- return (plugin_unregister (list_data_set, name));
-}
+ llentry_t *e;
+ data_set_t *ds;
+
+ e = llist_search (list_data_set, name);
+
+ if (e == NULL)
+ return (-1);
+
+ llist_remove (list_data_set, e);
+ ds = (data_set_t *) e->value;
+ llentry_destroy (e);
+
+ sfree (ds->ds);
+ sfree (ds);
+
+ return (0);
+} /* int plugin_unregister_data_set */
int plugin_unregister_log (const char *name)
{
diff --git a/src/types_list.c b/src/types_list.c
index 6fce0190f3046405506b0ea83fc7ba6e8d5aa5ee..3963897e02e1c923e0642eb94b69efee4cfae8b0 100644 (file)
--- a/src/types_list.c
+++ b/src/types_list.c
ds->type, ds->ds_num, (void *) ds->ds);
plugin_register_data_set (ds);
- /* Do NOT free `ds' and `ds->ds', because it's NOT copied by
- * `plugin_register_data_set'!. */
+
+ sfree (ds->ds);
+ sfree (ds);
} /* void parse_line */
static void parse_file (FILE *fh)