From patchwork Thu Aug 9 13:38:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 176160 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A28592C00C7 for ; Fri, 10 Aug 2012 01:02:19 +1000 (EST) Received: from localhost ([::1]:33860 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzSy0-0003FF-Qd for incoming@patchwork.ozlabs.org; Thu, 09 Aug 2012 09:40:00 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzSxU-00028J-7y for qemu-devel@nongnu.org; Thu, 09 Aug 2012 09:39:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzSxM-0003qv-5D for qemu-devel@nongnu.org; Thu, 09 Aug 2012 09:39:28 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:34613) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzSxL-0003qC-VA for qemu-devel@nongnu.org; Thu, 09 Aug 2012 09:39:20 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp12so868953pbb.4 for ; Thu, 09 Aug 2012 06:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=vDzVlOqwvRihui5yJuSGMdQEnuP5w/znaAqLrrn6jwU=; b=yS7od+Q0qL7/e8FjMuQDUHjlH29rr91Vxywo1wkF1nfxyjxwhzW8/qw+tnKEx3JMs5 hnUrZmm/c/1AhEtmLHmMvvKHfWXOKVD6ozC58CB0eQff4LcoUXpO+Qqdrs1hd4gQWqps dcyu+xJim7Ismf7ffdZyCWTjVOYmZCpvu1F/2FsySPmHrKfdej8Gvrcir9Z3yuSC4z4S Ypq1OifGtIwDQWDlRv09Rtovz0OdReTOPOWh6MPqgrt60Ik1P+LqQyYag6uVviCs+4/F Uu66I3TOHwmYzutD54+KBgr6QY314i9x5YBO6mRxvMyZ5n5vtVwBmJgnT0FmveS5cZEL 2Kuw== Received: by 10.68.241.35 with SMTP id wf3mr4251987pbc.102.1344519559495; Thu, 09 Aug 2012 06:39:19 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id qa2sm788320pbb.21.2012.08.09.06.39.16 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 09 Aug 2012 06:39:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 9 Aug 2012 15:38:25 +0200 Message-Id: <1344519511-18147-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1344519511-18147-1-git-send-email-pbonzini@redhat.com> References: <1344519511-18147-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Subject: [Qemu-devel] [PATCH 1/7] iscsi: do not leak initiator_name 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 The argument of iscsi_create_context is never freed by libiscsi, which in fact calls strdup on it. Avoid a leak. Signed-off-by: Paolo Bonzini --- block/iscsi.c | 33 ++++++++++++++++----------------- 1 file modificato, 16 inserzioni(+), 17 rimozioni(-) diff --git a/block/iscsi.c b/block/iscsi.c index 993a86d..94063ab 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -943,7 +943,7 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) error_report("Failed to parse URL : %s %s", filename, iscsi_get_error(iscsi)); ret = -EINVAL; - goto failed; + goto out; } memset(iscsilun, 0, sizeof(IscsiLun)); @@ -954,13 +954,13 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) if (iscsi == NULL) { error_report("iSCSI: Failed to create iSCSI context."); ret = -ENOMEM; - goto failed; + goto out; } if (iscsi_set_targetname(iscsi, iscsi_url->target)) { error_report("iSCSI: Failed to set target name."); ret = -EINVAL; - goto failed; + goto out; } if (iscsi_url->user != NULL) { @@ -969,7 +969,7 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) if (ret != 0) { error_report("Failed to set initiator username and password"); ret = -EINVAL; - goto failed; + goto out; } } @@ -977,13 +977,13 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) if (parse_chap(iscsi, iscsi_url->target) != 0) { error_report("iSCSI: Failed to set CHAP user/password"); ret = -EINVAL; - goto failed; + goto out; } if (iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL) != 0) { error_report("iSCSI: Failed to set session type to normal."); ret = -EINVAL; - goto failed; + goto out; } iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C); @@ -1004,7 +1004,7 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) != 0) { error_report("iSCSI: Failed to start async connect."); ret = -EINVAL; - goto failed; + goto out; } while (!task.complete) { @@ -1015,11 +1015,7 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) error_report("iSCSI: Failed to connect to LUN : %s", iscsi_get_error(iscsi)); ret = -EINVAL; - goto failed; - } - - if (iscsi_url != NULL) { - iscsi_destroy_url(iscsi_url); + goto out; } /* Medium changer or tape. We dont have any emulation for this so this must @@ -1031,19 +1027,22 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) bs->sg = 1; } - return 0; + ret = 0; -failed: +out: if (initiator_name != NULL) { g_free(initiator_name); } if (iscsi_url != NULL) { iscsi_destroy_url(iscsi_url); } - if (iscsi != NULL) { - iscsi_destroy_context(iscsi); + + if (ret) { + if (iscsi != NULL) { + iscsi_destroy_context(iscsi); + } + memset(iscsilun, 0, sizeof(IscsiLun)); } - memset(iscsilun, 0, sizeof(IscsiLun)); return ret; }