]> sigrok.org Git - libsigrok.git/commitdiff
fluke-45: free memory that was allocated by SCPI get routines
authorGerhard Sittig <redacted>
Sun, 16 May 2021 12:40:00 +0000 (14:40 +0200)
committerGerhard Sittig <redacted>
Sat, 22 May 2021 06:06:58 +0000 (08:06 +0200)
The SCPI get routines may allocate memory for response data which
callers have to free after use.

This implementation is incomplete. The fluke-45 driver's context holds
a "global" copy of the most recently received response. While the data
is freed in the next receive call, one item remains allocated for the
driver's remaining life time. Which is considered non-critical.

Also moves an operator in a complex multi-line expression to a different
location to follow the project's style.

This addresses part of bug #1683.

src/hardware/fluke-45/api.c
src/hardware/fluke-45/protocol.c

index 16c7dc03da23b06437b5eb633040d391539a33c5..2e80b6bfaae9b563a1d6ba4d78c7089b45f299ab 100644 (file)
@@ -78,16 +78,20 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        sr_scpi_get_string(scpi, "ECHO-TEST", &response);
        if (response && strcmp(response, "ECHO-TEST") == 0) {
                sr_err("Serial port ECHO is ON. Please turn it OFF!");
+               g_free(response);
                return NULL;
        }
+       g_free(response);
 #endif
 
        /* Get device IDN. */
        if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
+               sr_scpi_hw_info_free(hw_info);
                sr_info("Couldn't get IDN response, retrying.");
                sr_scpi_close(scpi);
                sr_scpi_open(scpi);
                if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
+                       sr_scpi_hw_info_free(hw_info);
                        sr_info("Couldn't get IDN response.");
                        return NULL;
                }
index 5d9c3793e8b119da0c6198c648181845d43908ad..16489007b830aeb02f8f5ce993054a11b8463072 100644 (file)
@@ -332,6 +332,7 @@ SR_PRIV int fl45_scpi_get_response(const struct sr_dev_inst *sdi, char *cmd)
                 * If the response is a prompt then ignore and read the next
                 * response in the buffer.
                 */
+               g_free(devc->response);
                devc->response = NULL;
                /* Now attempt to read again. */
                if (sr_scpi_get_string(sdi->conn, NULL, &devc->response) != SR_OK)
@@ -339,9 +340,10 @@ SR_PRIV int fl45_scpi_get_response(const struct sr_dev_inst *sdi, char *cmd)
        }
 
        /* NULL RS232 error prompts. */
-       if (strcmp(devc->response, "!>") == 0
-           || (strcmp(devc->response, "?>") == 0)) {
+       if (strcmp(devc->response, "!>") == 0 ||
+           (strcmp(devc->response, "?>") == 0)) {
                /* Unable to execute CMD. */
+               g_free(devc->response);
                devc->response = NULL;
        }