On 07/13/2014 05:59 AM, Peter Stuge wrote:
Peter A. Bigot wrote:
From 24f0ffd6f74c948d6838535af3e2418cc544dbac Mon Sep 17 00:00:00 2001
From: "Peter A. Bigot" <[email protected]>
Date: Sun, 13 Jul 2014 05:02:56 -0500
Subject: [PATCH] read_async: rework USB buffer management to avoid libusb API
violation
rtl_sdr on 64-bit Ubuntu 12.04 generates segfaults when interrupted
because the buffer used by a transfer initiated in rtlsdr_read_async()
was freed before the corresponding callback had been processed.
This commit reworks the async buffer management so that the callback is
responsible for freeing the buffer during the cancellation process and
ensures that the async call does not return until all buffers have been
released.
Yes, this seems like a good idea. Thanks!
Is there interest from the rtl-sdr maintainers in my pursuing this?
I ask because I keep getting close, but haven't conquered the edge
cases. In particular, when things go wrong I can still get hangs or
segfaults, because libusb_submit_transfer() and libusb_cancel_transfer()
do not give reliable information about whether the callback will be
subsequently be called: even with error returns, sometimes it is and
sometimes it isn't. There may be a way to determine from the specific
error value, but that behavior isn't documented. Without well-defined
behavior, I can't tell when it's safe to release the transfer buffer.
Personally, I'd like to see this made robust and could keep working on
it along a couple paths, but if there's little interest in taking the
patches I'll just go with something that works in my environment with
the specific libusb versions I have to deal with.
Peter