]> sigrok.org Git - libsigrok.git/commitdiff
lecroy-xstream: Fix memory leak
authorBert Vermeulen <redacted>
Fri, 4 Oct 2024 08:12:16 +0000 (10:12 +0200)
committerSoeren Apel <redacted>
Mon, 7 Oct 2024 20:58:22 +0000 (22:58 +0200)
Inspired by https://github.com/sigrokproject/libsigrok/pull/162
Thanks Lucien Murray-Pitts.

src/hardware/lecroy-xstream/protocol.c

index 8cc2bbd3b060c03b99f9fb49465c7fc5000848bd..81b2fd529bd157ee2dec2c03a3ec7ec491c288e0 100644 (file)
@@ -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;