diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2014-08-26 23:36:12 -0700 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2014-09-06 23:11:23 -0700 |
commit | b72f4cf77edb1975cada8aab5ae63361c68c5992 (patch) | |
tree | 41074a0a363dcac8d54f96c097806c5f71225f3f | |
parent | a0d37149dc7a51e8122ae666783333cde321bc44 (diff) | |
download | libusb-b72f4cf77edb1975cada8aab5ae63361c68c5992.tar.gz |
io: Fix memory leaks in usbi_io_init()
* If the hotplug pipe failed to be created, the usbi_pollfd for the
control pipe was being leaked.
* If the usbi_pollfd for timerfd failed to be added, the usbi_pollfd
for the hotplug pipe was being leaked.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r-- | libusb/io.c | 11 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/libusb/io.c b/libusb/io.c index 723ed0c..eb6f41b 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1134,7 +1134,7 @@ int usbi_io_init(struct libusb_context *ctx) r = usbi_pipe(ctx->hotplug_pipe); if (r < 0) { r = LIBUSB_ERROR_OTHER; - goto err; + goto err_remove_pipe; } r = usbi_add_pollfd(ctx, ctx->hotplug_pipe[0], POLLIN); @@ -1148,9 +1148,8 @@ int usbi_io_init(struct libusb_context *ctx) usbi_dbg("using timerfd for timeouts"); r = usbi_add_pollfd(ctx, ctx->timerfd, POLLIN); if (r < 0) { - usbi_remove_pollfd(ctx, ctx->ctrl_pipe[0]); close(ctx->timerfd); - goto err_close_hp_pipe; + goto err_remove_hp_pipe; } } else { usbi_dbg("timerfd not available (code %d error %d)", ctx->timerfd, errno); @@ -1160,9 +1159,15 @@ int usbi_io_init(struct libusb_context *ctx) return 0; +#ifdef USBI_TIMERFD_AVAILABLE +err_remove_hp_pipe: + usbi_remove_pollfd(ctx, ctx->hotplug_pipe[0]); +#endif err_close_hp_pipe: usbi_close(ctx->hotplug_pipe[0]); usbi_close(ctx->hotplug_pipe[1]); +err_remove_pipe: + usbi_remove_pollfd(ctx, ctx->ctrl_pipe[0]); err_close_pipe: usbi_close(ctx->ctrl_pipe[0]); usbi_close(ctx->ctrl_pipe[1]); diff --git a/libusb/version_nano.h b/libusb/version_nano.h index d6d2c7d..6841c9c 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10916 +#define LIBUSB_NANO 10917 |