From patchwork Wed Sep 25 14:00:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 277869 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 1FB6B2C0334 for ; Thu, 26 Sep 2013 00:02:39 +1000 (EST) Received: from localhost ([::1]:52902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOpfp-0002mC-7N for incoming@patchwork.ozlabs.org; Wed, 25 Sep 2013 10:02:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOpfQ-0002kT-HK for qemu-devel@nongnu.org; Wed, 25 Sep 2013 10:02:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VOpfL-0005vE-Gl for qemu-devel@nongnu.org; Wed, 25 Sep 2013 10:02:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34939) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOpfL-0005v7-9w; Wed, 25 Sep 2013 10:02:07 -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 r8PE0xBQ030669 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 25 Sep 2013 10:01:00 -0400 Received: from localhost (ovpn-112-32.ams2.redhat.com [10.36.112.32]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8PE0vs4018068; Wed, 25 Sep 2013 10:00:58 -0400 From: Stefan Hajnoczi To: Date: Wed, 25 Sep 2013 16:00:48 +0200 Message-Id: <1380117648-17625-1-git-send-email-stefanha@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 Cc: Kevin Wolf , Michael Roth , Stefan Hajnoczi , qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH v2] rbd: avoid qemu_rbd_snap_list() memory leaks 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 When there are no snapshots qemu_rbd_snap_list() returns 0 and the snapshot table pointer is NULL. Don't forget to free the snaps buffer we allocated for librbd rbd_snap_list(). When the function succeeds don't forget to free the snaps buffer after calling rbd_snap_list_end(). Cc: qemu-stable@nongnu.org Signed-off-by: Stefan Hajnoczi --- block/rbd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/rbd.c b/block/rbd.c index 11086c3..6c65b21 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -943,7 +943,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs, do { snaps = g_malloc(sizeof(*snaps) * max_snaps); snap_count = rbd_snap_list(s->image, snaps, &max_snaps); - if (snap_count < 0) { + if (snap_count <= 0) { g_free(snaps); } } while (snap_count == -ERANGE); @@ -967,6 +967,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs, sn_info->vm_clock_nsec = 0; } rbd_snap_list_end(snaps); + g_free(snaps); done: *psn_tab = sn_tab;