From patchwork Fri May 31 17:56:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 247992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 739F32C008E for ; Sat, 1 Jun 2013 03:57:09 +1000 (EST) Received: from localhost ([::1]:54183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiTZb-0005Kp-J3 for incoming@patchwork.ozlabs.org; Fri, 31 May 2013 13:57:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiTZL-0005Kk-Uy for qemu-devel@nongnu.org; Fri, 31 May 2013 13:56:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UiTZL-0001SW-2t for qemu-devel@nongnu.org; Fri, 31 May 2013 13:56:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35335) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiTZK-0001SL-Rc for qemu-devel@nongnu.org; Fri, 31 May 2013 13:56:51 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4VHunX4014492 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 31 May 2013 13:56:49 -0400 Received: from garlic.s154.bnl.gov (vpn1-7-191.ams2.redhat.com [10.36.7.191]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r4VHulBl011621 for ; Fri, 31 May 2013 13:56:48 -0400 From: Alon Levy To: qemu-devel@nongnu.org Date: Fri, 31 May 2013 13:56:46 -0400 Message-Id: <1370023006-4639-1-git-send-email-alevy@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] libcacard/vscclient: fix leakage of socket on error paths X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Spotted by Coverity. Signed-off-by: Alon Levy --- libcacard/vscclient.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c index ac23647..9fcc548 100644 --- a/libcacard/vscclient.c +++ b/libcacard/vscclient.c @@ -618,18 +618,22 @@ connect_to_qemu( if (ret != 0) { /* Error */ fprintf(stderr, "getaddrinfo failed\n"); - return -1; + goto cleanup_socket; } if (connect(sock, server->ai_addr, server->ai_addrlen) < 0) { /* Error */ fprintf(stderr, "Could not connect\n"); - return -1; + goto cleanup_socket; } if (verbose) { printf("Connected (sizeof Header=%zd)!\n", sizeof(VSCMsgHeader)); } return sock; + +cleanup_socket: + close(sock); + return -1; } int