]> sigrok.org Git - libsigrok.git/commitdiff
sr: fx2lafw: Properly free transfer
authorLars-Peter Clausen <redacted>
Sun, 24 Jun 2012 10:08:59 +0000 (12:08 +0200)
committerUwe Hermann <redacted>
Wed, 27 Jun 2012 22:40:51 +0000 (00:40 +0200)
When freeing a transfer we also have to free the transfer buffer. We also have
to keep track of the number of allocated transfers and if the freed transfer was
the last one stop acquisition. This patch introduces a helper function which
takes care of all of this.

Signed-off-by: Lars-Peter Clausen <redacted>
hardware/fx2lafw/fx2lafw.c

index a1a131e5fb18834837c684e325464f463b9bb9df..d38a199923ed6f141f680798cd1369b18b513afc 100644 (file)
@@ -682,6 +682,20 @@ static void finish_acquisition(struct context *ctx)
        free(lupfd); /* NOT g_free()! */
 }
 
+static void free_transfer(struct libusb_transfer *transfer)
+{
+       struct context *ctx = transfer->user_data;
+
+       g_free(transfer->buffer);
+       transfer->buffer = NULL;
+       libusb_free_transfer(transfer);
+
+       ctx->submitted_transfers--;
+       if (ctx->submitted_transfers == 0)
+               finish_acquisition(ctx);
+
+}
+
 static void receive_transfer(struct libusb_transfer *transfer)
 {
        /* TODO: These statics have to move to the ctx struct. */
@@ -697,13 +711,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
         * transfer that come in.
         */
        if (ctx->num_samples == -1) {
-               if (transfer)
-                       libusb_free_transfer(transfer);
-
-               ctx->submitted_transfers--;
-               if (ctx->submitted_transfers == 0)
-                       finish_acquisition(ctx);
-
+               free_transfer(transfer);
                return;
        }
 
@@ -718,7 +726,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);
+               free_transfer(transfer);
                return; /* TODO: SR_ERR_MALLOC */
        }