From: Florian Forster Date: Thu, 3 May 2007 09:16:29 +0000 (+0200) Subject: types_list: Do not free `ds' and `dsrc' because it's not copied in `plugin_register_d... X-Git-Tag: collectd-4.0.0-rc7~1^2~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0c9a0c0e0abbe3668673f52abaa395584b2bb4e7;p=collectd.git types_list: Do not free `ds' and `dsrc' because it's not copied in `plugin_register_data_set'. This is a TODO. --- diff --git a/src/types_list.c b/src/types_list.c index 1bbf142b..6fce0190 100644 --- a/src/types_list.c +++ b/src/types_list.c @@ -95,37 +95,42 @@ static void parse_line (char *buf, size_t buf_len) { char *fields[64]; size_t fields_num; - data_set_t ds; + data_set_t *ds; int i; fields_num = strsplit (buf, fields, 64); if (fields_num < 2) return; - memset (&ds, '\0', sizeof (ds)); + ds = (data_set_t *) malloc (sizeof (data_set_t)); + if (ds == NULL) + return; + + memset (ds, '\0', sizeof (data_set_t)); - strncpy (ds.type, fields[0], sizeof (ds.type)); - ds.type[sizeof (ds.type) - 1] = '\0'; + strncpy (ds->type, fields[0], sizeof (ds->type)); + ds->type[sizeof (ds->type) - 1] = '\0'; - ds.ds_num = fields_num - 1; - ds.ds = (data_source_t *) calloc (ds.ds_num, sizeof (data_source_t)); - if (ds.ds == NULL) + ds->ds_num = fields_num - 1; + ds->ds = (data_source_t *) calloc (ds->ds_num, sizeof (data_source_t)); + if (ds->ds == NULL) return; - for (i = 0; i < ds.ds_num; i++) - if (parse_ds (ds.ds + i, fields[i + 1], strlen (fields[i + 1])) != 0) + for (i = 0; i < ds->ds_num; i++) + if (parse_ds (ds->ds + i, fields[i + 1], strlen (fields[i + 1])) != 0) { - sfree (ds.ds); + sfree (ds->ds); ERROR ("types_list: parse_line: Cannot parse data source #%i " - "of data set %s", i, ds.type); + "of data set %s", i, ds->type); return; } DEBUG ("parse_line: ds = {%s, %i, %p};", - ds.type, ds.ds_num, (void *) ds.ds); + ds->type, ds->ds_num, (void *) ds->ds); - plugin_register_data_set (&ds); - sfree (ds.ds); + plugin_register_data_set (ds); + /* Do NOT free `ds' and `ds->ds', because it's NOT copied by + * `plugin_register_data_set'!. */ } /* void parse_line */ static void parse_file (FILE *fh)