Skip to content

Commit

Permalink
iio: centralize context pdata free in iio_context_destroy()
Browse files Browse the repository at this point in the history
iio_context_destroy() calls the 'shutdown' hook/op. This free's the context
private data at the end.

This can be done also in iio_context_destroy(), since it's just a pointer
free. Also, since the context private data allocation is being moved in the
context.c file, it makes more sense to have it there.

This minimizes open-coding, and some duplication.

Signed-off-by: Alexandru Ardelean <[email protected]>
  • Loading branch information
commodo committed Oct 14, 2020
1 parent 4a72ef0 commit 08f46e5
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 6 deletions.
2 changes: 2 additions & 0 deletions context.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ void iio_context_destroy(struct iio_context *ctx)
free(ctx->xml);
if (ctx->description)
free(ctx->description);
if (ctx->pdata)
free(ctx->pdata);
free(ctx);
}

Expand Down
2 changes: 0 additions & 2 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ static void local_shutdown(struct iio_context *ctx)
iio_device_close(dev);
local_free_pdata(dev);
}

free(ctx->pdata);
}

/** Shrinks the first nb characters of a string
Expand Down
1 change: 0 additions & 1 deletion network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,6 @@ static void network_shutdown(struct iio_context *ctx)

iiod_client_destroy(pdata->iiod_client);
freeaddrinfo(pdata->addrinfo);
free(pdata);
}

static int network_get_version(const struct iio_context *ctx,
Expand Down
2 changes: 0 additions & 2 deletions serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,6 @@ static void serial_shutdown(struct iio_context *ctx)

free(pdata);
}

free(ctx_pdata);
}

static int serial_set_timeout(struct iio_context *ctx, unsigned int timeout)
Expand Down
1 change: 0 additions & 1 deletion usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ static void usb_shutdown(struct iio_context *ctx)

libusb_close(ctx->pdata->hdl);
libusb_exit(ctx->pdata->ctx);
free(ctx->pdata);
}

static int iio_usb_match_interface(const struct libusb_config_descriptor *desc,
Expand Down

0 comments on commit 08f46e5

Please sign in to comment.