Skip to content

Commit

Permalink
network: Fix buffer reuse
Browse files Browse the repository at this point in the history
iiod_client_open_unlocked() is executed before setup_cancel() is called.
This means the cancellable flag needs to be set to false while running
iiod_client_open_unlocked() otherwise undefined behavior might occur.

The cancellable flag is a per device flag that at the moment is only set to
false then the IIO network context is created and is set to true when a
buffer as been successfully create. This means when creating a buffer for a
device, destroying the buffer and then creating another buffer for the same
device the cancellable flag will be set to true when running
iiod_client_open_unlocked().

To avoid this set cancellable to false when creating a new buffer.

Signed-off-by: Lars-Peter Clausen <[email protected]>
  • Loading branch information
larsclausen committed Jan 29, 2018
1 parent e2d854e commit c8ac1c5
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ static int network_open(const struct iio_device *dev,

ppdata->io_ctx.fd = ret;
ppdata->io_ctx.cancelled = false;
ppdata->io_ctx.cancellable = false;
ppdata->io_ctx.timeout_ms = DEFAULT_TIMEOUT_MS;

ret = iiod_client_open_unlocked(pdata->iiod_client,
Expand Down

1 comment on commit c8ac1c5

@dNechita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely fixes the issue where Scopy couldn't connect through a network backend.
Great fix!

Please sign in to comment.