From b72f4cf77edb1975cada8aab5ae63361c68c5992 Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Tue, 26 Aug 2014 23:36:12 -0700 Subject: [PATCH] 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 --- libusb/io.c | 11 ++++++++--- 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 -- 2.7.4