From: Bert Vermeulen Date: Fri, 4 Oct 2024 08:12:16 +0000 (+0200) Subject: lecroy-xstream: Fix memory leak X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3385c04b45072d6d8db9b412a129640e0be90710;p=libsigrok.git lecroy-xstream: Fix memory leak Inspired by https://github.com/sigrokproject/libsigrok/pull/162 Thanks Lucien Murray-Pitts. --- diff --git a/src/hardware/lecroy-xstream/protocol.c b/src/hardware/lecroy-xstream/protocol.c index 8cc2bbd3..81b2fd52 100644 --- a/src/hardware/lecroy-xstream/protocol.c +++ b/src/hardware/lecroy-xstream/protocol.c @@ -274,6 +274,7 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi, unsigned int i, j; char command[MAX_COMMAND_SIZE]; char *tmp_str; + int ret; for (i = 0; i < config->analog_channels; i++) { g_snprintf(command, sizeof(command), "C%d:TRACE?", i + 1); @@ -287,13 +288,13 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi, if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK) return SR_ERR; - if (array_float_get(tmp_str, ARRAY_AND_SIZE(vdivs), &j) != SR_OK) { - g_free(tmp_str); + ret = array_float_get(tmp_str, ARRAY_AND_SIZE(vdivs), &j); + g_free(tmp_str); + if (ret != SR_OK) { sr_err("Could not determine array index for vertical div scale."); return SR_ERR; } - g_free(tmp_str); state->analog_channels[i].vdiv = j; g_snprintf(command, sizeof(command), "C%d:OFFSET?", i + 1); @@ -306,13 +307,13 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi, if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK) return SR_ERR; - - if (scope_state_get_array_option(tmp_str, config->coupling_options, - config->num_coupling_options, - &state->analog_channels[i].coupling) != SR_OK) + ret = scope_state_get_array_option(tmp_str, config->coupling_options, + config->num_coupling_options, + &state->analog_channels[i].coupling); + g_free(tmp_str); + if (ret != SR_OK) return SR_ERR; - g_free(tmp_str); } return SR_OK;