]> sigrok.org Git - libsigrok.git/commitdiff
fluke-45: fix minor memory leaks in the probe routine
authorGerhard Sittig <redacted>
Sat, 3 Nov 2018 13:52:00 +0000 (14:52 +0100)
committeruser <redacted>
Sat, 10 Nov 2018 17:26:30 +0000 (18:26 +0100)
Free the SCPI hardware info after successful model detection, too. Only
allocate the device instance when a supported model was found. Link the
device context earlier right after allocation, for easier verification.

src/hardware/fluke-45/api.c

index 9e045f0763b5e967c5e9ed9b4aa9094ffa6daadf..16c7dc03da23b06437b5eb633040d391539a33c5 100644 (file)
@@ -72,9 +72,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        char *response;
 #endif
 
-       sdi = g_malloc0(sizeof(struct sr_dev_inst));
-       sdi->conn = scpi;
-
 #if ECHO_TEST
        /* Test for serial port ECHO enabled. */
        response = NULL;
@@ -111,6 +108,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        }
 
        /* Set up device parameters. */
+       sdi = g_malloc0(sizeof(struct sr_dev_inst));
        sdi->vendor = g_strdup(model->vendor);
        sdi->model = g_strdup(model->model);
        sdi->version = g_strdup(hw_info->firmware_version);
@@ -118,10 +116,12 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        sdi->conn = scpi;
        sdi->driver = &fluke_45_driver_info;
        sdi->inst_type = SR_INST_SCPI;
+       sr_scpi_hw_info_free(hw_info);
 
        devc = g_malloc0(sizeof(struct dev_context));
        devc->num_channels = model->num_channels;
        devc->cmdset = cmdset;
+       sdi->priv = devc;
 
        /* Create channels. */
        for (i = 0; i < devc->num_channels; i++) {
@@ -129,8 +129,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
                sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, channel_name);
        }
 
-       sdi->priv = devc;
-
        return sdi;
 }