From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0X5T-00052m-VG for qemu-devel@nongnu.org; Fri, 27 Jun 2014 10:25:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0X5N-0003Cu-Km for qemu-devel@nongnu.org; Fri, 27 Jun 2014 10:25:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6135) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0X5N-0003As-DQ for qemu-devel@nongnu.org; Fri, 27 Jun 2014 10:25:05 -0400 From: Stefan Hajnoczi Date: Fri, 27 Jun 2014 16:24:50 +0200 Message-Id: <1403879093-786-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1403879093-786-1-git-send-email-stefanha@redhat.com> References: <1403879093-786-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 1/4] qemu-bridge-helper: Fix fd leak in main() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Gonglei , Stefan Hajnoczi From: Gonglei initialize fd and ctlfd, and close them at the end Signed-off-by: Gonglei Signed-off-by: Stefan Hajnoczi --- qemu-bridge-helper.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index 6a0974e..36eb3bc 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -229,7 +229,7 @@ int main(int argc, char **argv) unsigned long ifargs[4]; #endif int ifindex; - int fd, ctlfd, unixfd = -1; + int fd = -1, ctlfd = -1, unixfd = -1; int use_vnet = 0; int mtu; const char *bridge = NULL; @@ -436,7 +436,12 @@ int main(int argc, char **argv) /* profit! */ cleanup: - + if (fd >= 0) { + close(fd); + } + if (ctlfd >= 0) { + close(ctlfd); + } while ((acl_rule = QSIMPLEQ_FIRST(&acl_list)) != NULL) { QSIMPLEQ_REMOVE_HEAD(&acl_list, entry); g_free(acl_rule); -- 1.9.3