hameg-hmo: fix potential memory leak

Make sure to release the allocated "pod enabled" memory, too, when SCPI
communication during channel setup fails. Defer the return with an error
(instead of duplicating the free() invocation).

This was reported by clang's scan-build.
This commit is contained in:
Gerhard Sittig 2018-02-10 10:26:23 +01:00
parent f396351704
commit addbb09bf8
1 changed files with 8 additions and 3 deletions

View File

@ -509,6 +509,7 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi)
struct sr_channel *ch; struct sr_channel *ch;
struct dev_context *devc; struct dev_context *devc;
struct sr_scpi_dev_inst *scpi; struct sr_scpi_dev_inst *scpi;
int ret;
devc = sdi->priv; devc = sdi->priv;
scpi = sdi->conn; scpi = sdi->conn;
@ -559,19 +560,23 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi)
} }
} }
ret = SR_OK;
for (i = 0; i < model->digital_pods; i++) { for (i = 0; i < model->digital_pods; i++) {
if (state->digital_pods[i] == pod_enabled[i]) if (state->digital_pods[i] == pod_enabled[i])
continue; continue;
g_snprintf(command, sizeof(command), g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE], (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
i + 1, pod_enabled[i]); i + 1, pod_enabled[i]);
if (sr_scpi_send(scpi, command) != SR_OK) if (sr_scpi_send(scpi, command) != SR_OK) {
return SR_ERR; ret = SR_ERR;
break;
}
state->digital_pods[i] = pod_enabled[i]; state->digital_pods[i] = pod_enabled[i];
setup_changed = TRUE; setup_changed = TRUE;
} }
g_free(pod_enabled); g_free(pod_enabled);
if (ret != SR_OK)
return ret;
if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK) if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK)
return SR_ERR; return SR_ERR;