Fix a few memory leaks

The file list isn't freed when an error occurs, and the strings returned
from the lookup_enum function are dynamically allocated and thus should
be freed as well.
This commit is contained in:
Jef Driesen 2018-02-20 19:36:18 +01:00
parent 96bac1de13
commit 01ccb7ce4b
2 changed files with 12 additions and 0 deletions

View File

@ -504,10 +504,12 @@ static int get_file_list(suunto_eonsteel_device_t *eon, struct directory_entry *
sizeof(result), result);
if (rc < 0) {
ERROR(eon->base.context, "readdir failed");
file_list_free(de);
return -1;
}
if (rc < 8) {
ERROR(eon->base.context, "short readdir result");
file_list_free(de);
return -1;
}
nr = array_uint32_le(result);

View File

@ -674,6 +674,7 @@ static char *lookup_enum(const struct type_desc *desc, unsigned char value)
*/
static void sample_event_state_type(const struct type_desc *desc, struct sample_data *info, unsigned char type)
{
free(info->state_type);
info->state_type = lookup_enum(desc, type);
}
@ -705,6 +706,7 @@ static void sample_event_state_value(const struct type_desc *desc, struct sample
static void sample_event_notify_type(const struct type_desc *desc, struct sample_data *info, unsigned char type)
{
free(info->notify_type);
info->notify_type = lookup_enum(desc, type);
}
@ -747,6 +749,7 @@ static void sample_event_notify_value(const struct type_desc *desc, struct sampl
static void sample_event_warning_type(const struct type_desc *desc, struct sample_data *info, unsigned char type)
{
free(info->warning_type);
info->warning_type = lookup_enum(desc, type);
}
@ -785,6 +788,7 @@ static void sample_event_warning_value(const struct type_desc *desc, struct samp
static void sample_event_alarm_type(const struct type_desc *desc, struct sample_data *info, unsigned char type)
{
free(info->alarm_type);
info->alarm_type = lookup_enum(desc, type);
}
@ -1013,6 +1017,12 @@ suunto_eonsteel_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback
struct sample_data data = { eon, callback, userdata, 0 };
traverse_data(eon, traverse_samples, &data);
free(data.state_type);
free(data.notify_type);
free(data.warning_type);
free(data.alarm_type);
return DC_STATUS_SUCCESS;
}