summaryrefslogtreecommitdiffstats
path: root/dmi.c
diff options
context:
space:
mode:
authorStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2012-09-23 12:14:28 +0000
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2012-09-23 12:14:28 +0000
commit4e6d346c6ec0188aa309bfa2fe86ce52b9487ec6 (patch)
tree42f8ce222cd6f6607d0b1e12bb65ea11532b7d32 /dmi.c
parente0ff1652a60e3fdcd82e3def8c9d13b071a4d05d (diff)
downloadflashrom-4e6d346c6ec0188aa309bfa2fe86ce52b9487ec6.tar.gz
flashrom-4e6d346c6ec0188aa309bfa2fe86ce52b9487ec6.tar.bz2
flashrom-4e6d346c6ec0188aa309bfa2fe86ce52b9487ec6.zip
Fix memleaks in dmi.c
In dmi_init() we populate static char *dmistrings[] with values that get later compared in dmi_match(). Those strings are actually strduped in get_dmi_string() and hence need to be freed later. This patch accomplishes this by registering another shutdown method. Also, the tangling pointers are nulled when the memories are freed. This bug was found thanks to valgrind. Corresponding to flashrom svn r1604. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Diffstat (limited to 'dmi.c')
-rw-r--r--dmi.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/dmi.c b/dmi.c
index dfc78e9c0..a6e214615 100644
--- a/dmi.c
+++ b/dmi.c
@@ -144,16 +144,29 @@ static char *get_dmi_string(const char *string_name)
result = strdup(answerbuf);
if (!result)
- puts("WARNING: Out of memory - DMI support fails");
+ msg_perr("WARNING: Out of memory - DMI support fails");
return result;
}
+static int dmi_shutdown(void *data)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(dmistrings); i++) {
+ free(dmistrings[i]);
+ dmistrings[i] = NULL;
+ }
+ return 0;
+}
+
void dmi_init(void)
{
int i;
char *chassis_type;
+ if (register_shutdown(dmi_shutdown, NULL))
+ return;
+
has_dmi_support = 1;
for (i = 0; i < ARRAY_SIZE(dmidecode_names); i++) {
dmistrings[i] = get_dmi_string(dmidecode_names[i]);