From f8229bd77f038346e9ef18d84d44c49b16916abb Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Thu, 3 Sep 2009 16:54:20 +0000 Subject: fix freed memory usage in criteria_from_dmidecode and entries_matching_criteria, and some other warnings in dmi.c --- dmi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'dmi.c') diff --git a/dmi.c b/dmi.c index d316ed2..b927994 100644 --- a/dmi.c +++ b/dmi.c @@ -79,7 +79,7 @@ static char *get_after_colon(char *s) { } else return NULL; } -static struct category *lookup_category(const char *cat_name) { +static const struct category *lookup_category(const char *cat_name) { int i; for (i = 0; i < nb_categories; i++) if (streq(categories[i].cat_name, cat_name)) @@ -87,7 +87,7 @@ static struct category *lookup_category(const char *cat_name) { return NULL; } -static int lookup_field(struct category *category, const char *field_name) { +static int lookup_field(const struct category *category, const char *field_name) { unsigned int i; for (i = 0; i < category->nb_fields; i++) if (streq(category->fields[i], field_name)) @@ -108,9 +108,7 @@ static struct criteria criteria_from_dmidecode(void) { FILE *f; char buf[BUF_SIZE]; - struct criteria r; - - r.nb = 0; + struct criteria r = {0, NULL}; if (!(f = dmidecode_file ? fopen(dmidecode_file, "r") : popen("dmidecode", "r"))) { perror("dmidecode"); @@ -119,7 +117,7 @@ static struct criteria criteria_from_dmidecode(void) { r.criteria = malloc(sizeof(*r.criteria) * MAX_DEVICES); - struct category *category = NULL; + const struct category *category = NULL; /* dmidecode output is less indented as of 2.7 */ int tab_level = 1; @@ -155,7 +153,7 @@ static struct criteria criteria_from_dmidecode(void) { r.nb = 0; return r; } - realloc(r.criteria, sizeof(*r.criteria) * r.nb); + r.criteria = realloc(r.criteria, sizeof(*r.criteria) * r.nb); return r; } @@ -263,7 +261,7 @@ static struct dmi_entries entries_matching_criteria(struct criteria criteria) { foreach_indent(0, ifree(constraints[i])); fh_close(&f); - realloc(r.entries, sizeof(*r.entries) * r.nb); + r.entries = realloc(r.entries, sizeof(*r.entries) * r.nb); return r; } -- cgit v1.2.1