From patchwork Tue Jun 4 20:23:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 248855 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 125F62C00A0 for ; Wed, 5 Jun 2013 06:25:42 +1000 (EST) Received: from localhost ([::1]:33458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjxnY-0003Dv-3T for incoming@patchwork.ozlabs.org; Tue, 04 Jun 2013 16:25:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujxm6-0001HE-BC for qemu-devel@nongnu.org; Tue, 04 Jun 2013 16:24:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ujxm1-0005s3-HR for qemu-devel@nongnu.org; Tue, 04 Jun 2013 16:24:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26248) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujxm1-0005ry-A9; Tue, 04 Jun 2013 16:24:05 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r54KO41T010514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 4 Jun 2013 16:24:04 -0400 Received: from garlic.sbx07344.newyony.wayport.net (vpn1-5-107.ams2.redhat.com [10.36.5.107]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r54KNeZh022345; Tue, 4 Jun 2013 16:23:58 -0400 From: Alon Levy To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org Date: Tue, 4 Jun 2013 16:23:37 -0400 Message-Id: <1370377419-31788-3-git-send-email-alevy@redhat.com> In-Reply-To: <1370377419-31788-1-git-send-email-alevy@redhat.com> References: <1370377419-31788-1-git-send-email-alevy@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/5] 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 Reviewed-by: Peter Maydell --- libcacard/vscclient.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c index ac23647..5180d29 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: + closesocket(sock); + return -1; } int @@ -759,5 +763,6 @@ main( g_io_channel_unref(channel_socket); g_byte_array_unref(socket_to_send); + closesocket(sock); return 0; }