hameg-hmo: free memory that was allocated by SCPI get routines
authorGerhard Sittig <gerhard.sittig@gmx.net>
Sun, 16 May 2021 17:42:53 +0000 (19:42 +0200)
committerGerhard Sittig <gerhard.sittig@gmx.net>
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.

Move an existing assigment such that the initial assignment, the memory
allocation, use of response data, and resource release are in closer
proximity, and thus are easier to reason about during maintenance.
Behaviour does not change.

This is motivated by bug #1683.

src/hardware/hameg-hmo/protocol.c

index 3e15d3760543a7ab3da9332a356c5dd8eae7812d..26dac0cb037f34de3a8e370bc2d74a99285a799d 100644 (file)
@@ -1380,8 +1380,6 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
        (void)fd;
        (void)revents;
 
-       data = NULL;
-
        if (!(sdi = cb_data))
                return TRUE;
 
@@ -1410,6 +1408,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
         */
        switch (ch->type) {
        case SR_CHANNEL_ANALOG:
+               data = NULL;
                if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
                        if (data)
                                g_byte_array_free(data, TRUE);
@@ -1442,6 +1441,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
                data = NULL;
                break;
        case SR_CHANNEL_LOGIC:
+               data = NULL;
                if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
                        if (data)
                                g_byte_array_free(data, TRUE);