From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqJrw-0006j9-QZ for qemu-devel@nongnu.org; Mon, 17 Nov 2014 05:49:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqJrs-0004L8-0R for qemu-devel@nongnu.org; Mon, 17 Nov 2014 05:49:16 -0500 Message-ID: <5469D290.5080202@redhat.com> Date: Mon, 17 Nov 2014 11:48:48 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1416046008-7880-1-git-send-email-arei.gonglei@huawei.com> <1416046008-7880-7-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1416046008-7880-7-git-send-email-arei.gonglei@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 6/9] acl: fix memory leak List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: arei.gonglei@huawei.com, qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, mjt@tls.msk.ru, weidong.huang@huawei.com, peter.huangpeng@huawei.com, zhang.zhanghailiang@huawei.com On 15/11/2014 11:06, arei.gonglei@huawei.com wrote: > From: Gonglei > > If 'i != index' for all acl->entries, variable > entry leaks the storage it points to. > > Signed-off-by: Gonglei > --- > util/acl.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/util/acl.c b/util/acl.c > index 938b7ae..571d686 100644 > --- a/util/acl.c > +++ b/util/acl.c > @@ -132,7 +132,6 @@ int qemu_acl_insert(qemu_acl *acl, > const char *match, > int index) > { > - qemu_acl_entry *entry; > qemu_acl_entry *tmp; > int i = 0; > > @@ -142,13 +141,14 @@ int qemu_acl_insert(qemu_acl *acl, > return qemu_acl_append(acl, deny, match); > } > > - entry = g_malloc(sizeof(*entry)); > - entry->match = g_strdup(match); > - entry->deny = deny; > - > QTAILQ_FOREACH(tmp, &acl->entries, next) { > i++; > if (i == index) { > + qemu_acl_entry *entry; > + entry = g_malloc(sizeof(*entry)); > + entry->match = g_strdup(match); > + entry->deny = deny; > + > QTAILQ_INSERT_BEFORE(tmp, entry, next); > acl->nentries++; > break; > This should never happen, but the patch doesn't hurt either. Paolo