diff options
authorGerhard Sittig <gerhard.sittig@gmx.net>2016-11-06 12:08:02 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2017-01-07 15:51:32 +0100
commit40a75c8e9732992e80e055c995edd73f1ff07f2a (patch)
parent2d224dbae735e5d3ea39cbafcd6d280cbd112c31 (diff)
hameg-hmo: Release enabled channels when acquisition start fails
Commit db81fbb58261 made sure to release a potentially previously allocated list of enabled channels before (re-)building the list in the current invocation of acquisition start. This commit frees the memory in the error path near the failed creation already, which reduces the period of time where unused resources are held, and eliminates a memory leak when acquisition is not stopped after failed start. Both approaches can coexist. Freeing an empty list is perfectly fine.
1 files changed, 10 insertions, 2 deletions
diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c
index fe32262..92f5ab6 100644
--- a/src/hardware/hameg-hmo/api.c
+++ b/src/hardware/hameg-hmo/api.c
@@ -705,6 +705,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
struct sr_channel *ch;
struct dev_context *devc;
struct sr_scpi_dev_inst *scpi;
+ int ret;
if (sdi->status != SR_ST_ACTIVE)
@@ -734,12 +735,14 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
if (hmo_check_channels(devc->enabled_channels) != SR_OK) {
sr_err("Invalid channel configuration specified!");
- return SR_ERR_NA;
+ ret = SR_ERR_NA;
+ goto free_enabled;
if (hmo_setup_channels(sdi) != SR_OK) {
sr_err("Failed to setup channel configuration!");
- return SR_ERR;
+ ret = SR_ERR;
+ goto free_enabled;
sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
@@ -750,6 +753,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
devc->current_channel = devc->enabled_channels;
return hmo_request_data(sdi);
+ g_slist_free(devc->enabled_channels);
+ devc->enabled_channels = NULL;
+ return ret;
static int dev_acquisition_stop(struct sr_dev_inst *sdi)