The SCPI get routines may allocate memory for response data which
callers have to free after use.
The implemented approach is modelled after pull request 114 by
Matti Eiden, to get the leak fixes in while the PR is queued.
This addresses part of bug #1683.
Submitted-By: Matti Eiden <redacted>
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
g_usleep(s);
} while (out == 0);
g_usleep(s);
} while (out == 0);
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
g_usleep(s);
/* XXX
* Now this loop condition looks suspicious! A bitwise
g_usleep(s);
/* XXX
* Now this loop condition looks suspicious! A bitwise
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
if (out == DEVICE_STATE_TRIG_RDY) {
siglent_sds_set_wait_event(devc, WAIT_TRIGGER);
} else if (out == DEVICE_STATE_DATA_TRIG_RDY) {
if (out == DEVICE_STATE_TRIG_RDY) {
siglent_sds_set_wait_event(devc, WAIT_TRIGGER);
} else if (out == DEVICE_STATE_DATA_TRIG_RDY) {
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
if (out == DEVICE_STATE_TRIG_RDY) {
siglent_sds_set_wait_event(devc, WAIT_TRIGGER);
} else if (out == DEVICE_STATE_DATA_TRIG_RDY) {
if (out == DEVICE_STATE_TRIG_RDY) {
siglent_sds_set_wait_event(devc, WAIT_TRIGGER);
} else if (out == DEVICE_STATE_DATA_TRIG_RDY) {
/* Coupling. */
for (i = 0; i < devc->model->analog_channels; i++) {
cmd = g_strdup_printf("C%d:CPL?", i + 1);
/* Coupling. */
for (i = 0; i < devc->model->analog_channels; i++) {
cmd = g_strdup_printf("C%d:CPL?", i + 1);
+ g_free(devc->coupling[i]);
+ devc->coupling[i] = NULL;
res = sr_scpi_get_string(sdi->conn, cmd, &devc->coupling[i]);
g_free(cmd);
if (res != SR_OK)
res = sr_scpi_get_string(sdi->conn, cmd, &devc->coupling[i]);
g_free(cmd);
if (res != SR_OK)
/* Trigger slope. */
cmd = g_strdup_printf("%s:TRSL?", devc->trigger_source);
/* Trigger slope. */
cmd = g_strdup_printf("%s:TRSL?", devc->trigger_source);
+ g_free(devc->trigger_slope);
+ devc->trigger_slope = NULL;
res = sr_scpi_get_string(sdi->conn, cmd, &devc->trigger_slope);
g_free(cmd);
if (res != SR_OK)
res = sr_scpi_get_string(sdi->conn, cmd, &devc->trigger_slope);
g_free(cmd);
if (res != SR_OK)
g_free(cmd);
samplerate_scope = 0;
fvalue = 0;
g_free(cmd);
samplerate_scope = 0;
fvalue = 0;
+ if (res != SR_OK) {
+ g_free(sample_points_string);
if (g_strstr_len(sample_points_string, -1, "Mpts") != NULL) {
sample_points_string[strlen(sample_points_string) - 4] = '\0';
if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK) {
sr_dbg("Invalid float converted from scope response.");
if (g_strstr_len(sample_points_string, -1, "Mpts") != NULL) {
sample_points_string[strlen(sample_points_string) - 4] = '\0';
if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK) {
sr_dbg("Invalid float converted from scope response.");
+ g_free(sample_points_string);
return SR_ERR;
}
samplerate_scope = fvalue * 1000000;
return SR_ERR;
}
samplerate_scope = fvalue * 1000000;
sample_points_string[strlen(sample_points_string) - 4] = '\0';
if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK) {
sr_dbg("Invalid float converted from scope response.");
sample_points_string[strlen(sample_points_string) - 4] = '\0';
if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK) {
sr_dbg("Invalid float converted from scope response.");
+ g_free(sample_points_string);
return SR_ERR;
}
samplerate_scope = fvalue * 10000;
return SR_ERR;
}
samplerate_scope = fvalue * 10000;