fluke-45: free memory that was allocated by SCPI get routines
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.
This commit is contained in:
parent
9b915e3a41
commit
c9cfcd2591
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue