mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-26 22:52:34 +02:00
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>
This commit is contained in:
parent
e0ff1652a6
commit
4e6d346c6e
15
dmi.c
15
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]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user