From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0ED6C07E9A for ; Wed, 14 Jul 2021 07:31:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 44C3D613AA for ; Wed, 14 Jul 2021 07:31:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44C3D613AA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3ZMS-0004vh-De for qemu-devel@archiver.kernel.org; Wed, 14 Jul 2021 03:31:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZHl-0006jR-Ih for qemu-devel@nongnu.org; Wed, 14 Jul 2021 03:26:25 -0400 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]:36675) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3ZHj-0008Qr-MM for qemu-devel@nongnu.org; Wed, 14 Jul 2021 03:26:25 -0400 Received: by mail-yb1-xb35.google.com with SMTP id v189so1673682ybg.3 for ; Wed, 14 Jul 2021 00:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8bTW6jNHIUGkVxAIMQ/XAPqoC4sdhQbX8mC2jIbGtEA=; b=Nic/LwOf4YdU9CCV+XTYqgQXHaXgEzKjD3n5XkSfdyDMrkrhPmz1NlPa1rLD+gk4TR HD7EkF2qHL4mnkshEMFk+JavxuTwYsHIwiu/EE3fhhitaPj28UQg4OrV1BqJb2fafmY4 MK3glJx8oir9C0n2RY0uc9MI/X+AcE5AzDBOODhyt7ikUZXdV6m7RDiulGCwVdXGOttD nMLSoVJ2dsElk1+cjO4Dfhzkmof5Lhlfvhkz4k3fEt5VoieV/cD2hx9BGlIfo2ZQye41 JjLw6oBPN0CSeMz2JbV7HCzC12+lXiKV3UwGSnvX4BQXitRenFagq8qomuZAOTpMBeXV mBPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8bTW6jNHIUGkVxAIMQ/XAPqoC4sdhQbX8mC2jIbGtEA=; b=sopyu7FHhHjVsPYT4k/hB0KtvIoDdtR4eje59Xc9YycgU0mfRYaEupvW51K+nJSmMb a20P6wZ0li8chZQFSbYSvwtoFeLrhysC7AGsg01KJmQj/i7+546NItSStkaBH/BCPPW1 oruE2u9euBYaHCBr1x75RCnux5WV3m2cU26zIEpgUiCzzlBNSUMTN3/KBZU6ruhVtdyF UlDn/YNMiQ2RJ3WjKHpGDO+IbsyzT1LXZDJtG71jtdFVEd6TVgYp7eiywctqugCU52vn e/jc4ZfrI0VhOBoj2n5xphytQzbaP64ATE2KZlZBTyiPnaMqvSUKftvpHkkBnX5oFLfO h4pA== X-Gm-Message-State: AOAM5300QfyklIGNWTbSD64+ATYTUCwPi5onyWyAzoUH0AShitiRuduE bW5iEtwEw7H95GFd1ZvJVLv8eJMRYiFKqjC7FE5QNA== X-Google-Smtp-Source: ABdhPJympwlXKCholSeqCXCYZS9k0sGzAbqKN6gZAo7elG7GVzlsLOPRJX+DVq9VYWyhNkCH1Tjt+Plb2/UbvhLcbyo= X-Received: by 2002:a25:587:: with SMTP id 129mr11401756ybf.379.1626247582586; Wed, 14 Jul 2021 00:26:22 -0700 (PDT) MIME-Version: 1.0 References: <20210610155811.3313927-1-konstantin@daynix.com> In-Reply-To: From: Konstantin Kostiuk Date: Wed, 14 Jul 2021 10:26:11 +0300 Message-ID: Subject: Re: [PATCH v2] qga-win: Free GMatchInfo properly To: Michael Roth Content-Type: multipart/alternative; boundary="0000000000007a26e005c71045fd" Received-SPF: none client-ip=2607:f8b0:4864:20::b35; envelope-from=konstantin@daynix.com; helo=mail-yb1-xb35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?Q?Daniel_P=2E_Berrang=C3=A9?= , Developers , Michael Roth Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --0000000000007a26e005c71045fd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable CC Michael Roth On Thu, Jun 10, 2021 at 7:14 PM Daniel P. Berrang=C3=A9 wrote: > On Thu, Jun 10, 2021 at 07:08:36PM +0300, Konstantin Kostiuk wrote: > > On Thu, Jun 10, 2021 at 7:02 PM Daniel P. Berrang=C3=A9 > > wrote: > > > > > On Thu, Jun 10, 2021 at 06:58:11PM +0300, Kostiantyn Kostiuk wrote: > > > > The g_regex_match function creates match_info even if it > > > > returns FALSE. So we should always call g_match_info_free. > > > > A better solution is using g_autoptr for match_info variable. > > > > > > > > Signed-off-by: Kostiantyn Kostiuk > > > > --- > > > > qga/commands-win32.c | 3 +-- > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > diff --git a/qga/commands-win32.c b/qga/commands-win32.c > > > > index 300b87c859..785a5cc6b2 100644 > > > > --- a/qga/commands-win32.c > > > > +++ b/qga/commands-win32.c > > > > @@ -2494,7 +2494,7 @@ GuestDeviceInfoList > *qmp_guest_get_devices(Error > > > **errp) > > > > continue; > > > > } > > > > for (j =3D 0; hw_ids[j] !=3D NULL; j++) { > > > > - GMatchInfo *match_info; > > > > + g_autoptr(GMatchInfo) match_info; > > > > > > This should be initialized to NULL otherwise... > > > > > > > GuestDeviceIdPCI *id; > > > > if (!g_regex_match(device_pci_re, hw_ids[j], 0, > > > &match_info)) { > > > > continue; > > > > > > this continue will trigger freeing of unintialized memory > > > > > > > But we always call match_info, so match_info is always initialized. > > The g_regex_match function creates match_info even if it returns FALSE. > > Opps, yes, you are right. > > Reviewed-by: Daniel P. Berrang=C3=A9 > > > Regards, > Daniel > -- > |: https://berrange.com -o- > https://www.flickr.com/photos/dberrange :| > |: https://libvirt.org -o- > https://fstop138.berrange.com :| > |: https://entangle-photo.org -o- > https://www.instagram.com/dberrange :| > > --0000000000007a26e005c71045fd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
CC Michael Roth

On Thu, Jun 10, 2021 at 7:14 PM Daniel = P. Berrang=C3=A9 <berrange@redhat= .com> wrote:
On Thu, Jun 10, 2021 at 07:08:36PM +0300, Konstantin Kostiuk wrote:
> On Thu, Jun 10, 2021 at 7:02 PM Daniel P. Berrang=C3=A9 <berrange@redhat.com><= br> > wrote:
>
> > On Thu, Jun 10, 2021 at 06:58:11PM +0300, Kostiantyn Kostiuk wrot= e:
> > > The g_regex_match function creates match_info even if it
> > > returns FALSE. So we should always call g_match_info_free. > > > A better solution is using g_autoptr for match_info variable= .
> > >
> > > Signed-off-by: Kostiantyn Kostiuk <konstantin@daynix.com>
> > > ---
> > >=C2=A0 qga/commands-win32.c | 3 +--
> > >=C2=A0 1 file changed, 1 insertion(+), 2 deletions(-)
> > >
> > > diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> > > index 300b87c859..785a5cc6b2 100644
> > > --- a/qga/commands-win32.c
> > > +++ b/qga/commands-win32.c
> > > @@ -2494,7 +2494,7 @@ GuestDeviceInfoList *qmp_guest_get_dev= ices(Error
> > **errp)
> > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue; > > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for (j =3D 0; hw_ids[j] != =3D NULL; j++) {
> > > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 GMatchInfo *match= _info;
> > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 g_autoptr(GMatchI= nfo) match_info;
> >
> > This should be initialized to NULL otherwise...
> >
> > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 GuestDeviceI= dPCI *id;
> > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!g_regex= _match(device_pci_re, hw_ids[j], 0,
> > &match_info)) {
> > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 continue;
> >
> > this continue will trigger freeing of unintialized memory
> >
>
> But we always call match_info, so match_info is always initialized. > The g_regex_match function creates match_info even if it returns FALSE= .

Opps, yes, you are right.

Reviewed-by: Daniel P. Berrang=C3=A9 <berrange@redhat.com>


Regards,
Daniel
--
|: ht= tps://berrange.com=C2=A0 =C2=A0 =C2=A0 -o-=C2=A0 =C2=A0 h= ttps://www.flickr.com/photos/dberrange :|
|: htt= ps://libvirt.org=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-o-=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 https://fstop138.berrange.com :|
|: https://entangle-photo.org=C2=A0 =C2=A0 -o-=C2=A0 =C2=A0 = https://www.instagram.com/dberrange :|

--0000000000007a26e005c71045fd--