]> sigrok.org Git - libsigrok.git/blobdiff - src/scpi/scpi_vxi.c
scpi_vxi: fix memory leak for SCPI response data in VXI support code
[libsigrok.git] / src / scpi / scpi_vxi.c
index 2b8e50dee5688ce3a7383e29949ee959086d5dc2..9b38efdab1c83581146b3fe5a0344019bce49d44 100644 (file)
@@ -195,10 +195,16 @@ static int scpi_vxi_read_data(void *priv, char *buf, int maxlen)
        if (!read_resp || read_resp->error) {
                sr_err("Device read failed for %s with error %ld",
                       vxi->address, read_resp ? read_resp->error : 0);
+               if (read_resp) {
+                       g_free(read_resp->data.data_val);
+                       read_resp->data.data_val = NULL;
+               }
                return SR_ERR;
        }
 
        memcpy(buf, read_resp->data.data_val, read_resp->data.data_len);
+       g_free(read_resp->data.data_val);
+       read_resp->data.data_val = NULL;
        vxi->read_complete = read_resp->reason & (RRR_TERM | RRR_END);
        return read_resp->data.data_len;  /* actual number of bytes received */
 }