There are a few memory leaks in the receive_transfer transfer function. The most
serve of them is that a sample buffer is not freed if the triggered has not
matched yet, which causes a sigrok process which is waiting for a trigger to
consume several megabytes of memory within seconds. The other leaks are on the
error paths in that function.

Signed-off-by: Lars-Peter Clausen <[email protected]>
---
 libsigrok/hardware/fx2lafw/fx2lafw.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libsigrok/hardware/fx2lafw/fx2lafw.c 
b/libsigrok/hardware/fx2lafw/fx2lafw.c
index 5d8b49b..afdd950 100644
--- a/libsigrok/hardware/fx2lafw/fx2lafw.c
+++ b/libsigrok/hardware/fx2lafw/fx2lafw.c
@@ -706,6 +706,7 @@ static void receive_transfer(struct libusb_transfer 
*transfer)
        /* Fire off a new request. */
        if (!(new_buf = g_try_malloc(4096))) {
                sr_err("fx2lafw: %s: new_buf malloc failed.", __func__);
+               libusb_free_transfer(transfer);
                return; /* TODO: SR_ERR_MALLOC */
        }
 
@@ -726,6 +727,7 @@ static void receive_transfer(struct libusb_transfer 
*transfer)
                         */
                        abort_acquisition(ctx);
                }
+               g_free(cur_buf);
                return;
        } else {
                empty_transfer_count = 0;
@@ -798,7 +800,6 @@ static void receive_transfer(struct libusb_transfer 
*transfer)
                logic.unitsize = sample_width;
                logic.data = cur_buf + trigger_offset_bytes;
                sr_session_send(ctx->session_dev_id, &packet);
-               g_free(cur_buf);
 
                ctx->num_samples += cur_sample_count;
                if (ctx->limit_samples &&
@@ -811,6 +812,7 @@ static void receive_transfer(struct libusb_transfer 
*transfer)
                 * ratio-sized buffer.
                 */
        }
+       g_free(cur_buf);
 }
 
 static int hw_dev_acquisition_start(int dev_index, void *cb_data)
-- 
1.7.10


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to