From: David Engraf Date: Mon, 19 May 2008 14:13:38 +0000 (+0100) Subject: critical memory leak in handle_events X-Git-Tag: upstream/1.0.21~1044 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e44396a458ecea9e5edd9a7577e617571c76860d;p=platform%2Fupstream%2Flibusb.git critical memory leak in handle_events This patch closes a critical memory leak in handle_events. The fds variable is malloced but never freed. When I'm calling handle_events with a timeout of 0, my system runs out of memory after a few seconds. --- diff --git a/libusb/io.c b/libusb/io.c index 19b62c2..9bb3abb 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -930,10 +930,13 @@ static int handle_events(struct timeval *tv) r = poll(fds, nfds, timeout_ms); usbi_dbg("poll() returned %d", r); if (r == 0) { + free(fds); return handle_timeouts(); } else if (r == -1 && errno == EINTR) { + free(fds); return LIBUSB_ERROR_INTERRUPTED; } else if (r < 0) { + free(fds); usbi_err("poll failed %d err=%d\n", r, errno); return LIBUSB_ERROR_IO; } @@ -942,6 +945,7 @@ static int handle_events(struct timeval *tv) if (r) usbi_err("backend handle_events failed with error %d", r); + free(fds); return r; }