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 D0C6AC4338F for ; Wed, 28 Jul 2021 07:56:25 +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 6CB1560F9E for ; Wed, 28 Jul 2021 07:56:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6CB1560F9E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:60968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8eQS-00078K-Hm for qemu-devel@archiver.kernel.org; Wed, 28 Jul 2021 03:56:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8eOV-0003zx-Ft for qemu-devel@nongnu.org; Wed, 28 Jul 2021 03:54:23 -0400 Received: from mail-yb1-xb2b.google.com ([2607:f8b0:4864:20::b2b]:39672) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m8eOT-0003TU-Hs for qemu-devel@nongnu.org; Wed, 28 Jul 2021 03:54:23 -0400 Received: by mail-yb1-xb2b.google.com with SMTP id p145so1413978ybg.6 for ; Wed, 28 Jul 2021 00:54:21 -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=DjeOczhcqL3Id3xhMhFWu9Z8BY4v7Kv0f6BFxK8VYy0=; b=VFgZl+UKBbwU3iYJDzQwkNeMda6dEsCBWRvYDxtyjbrgouKDclR8VeM2M1ELHfYNi4 zd/M8fZ+/Hz3hZqoukKVlE5+Crjt1apyH4pIGQKYH461aOstM/e6JFBjC3c4ead1T//K 0digmMMIaXHmSZEKOYFJQFrvjZU8f+WvQNzNRqBnx3bfCDzi63mTuDCUdQ+h1e7HWmFU lC4tS3mHlhkvSQNmRFxJO93NiPdMeqg3B1NZagZ+tuFB46LibvprTiuxMH81Y5of5OCI 4oEdE5mSuFm3eOUcAxp/m17Vs3BvxJjWMAPhD4FtGfgnlyLG/PMUzMCz67+iCv1cI+WX dqKA== 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=DjeOczhcqL3Id3xhMhFWu9Z8BY4v7Kv0f6BFxK8VYy0=; b=G+RLuIrVx8CKy5dCfOlmXpWt78TnqjTDMYYMMw7eXpzoZNB6f1Eonl/hL4W+DUjSxD w0ILEac1sLPE7gCpc3ygNawAH4wzPb7eBAmlJcAfbXz3Vl41aBkkp65lOQjOGKWs9Dnr tRSn6tAF5lK3orqOseD3ODWyA7ieg5kxMSjW+Wm31b/VJt+2BzUDUnxEhS9dIC02+ir0 fvZ/k73kFyID60QbctWFWqzMTY3AjbKzWLkAJ8CzX1w4FHW2sICvLP1BFgAW7nxBgFX6 dR8ajxOd9sFr1tCqSn/JPWcCDBtLkUhu3afyWSgJYUMUkB1iCKer76m8/AOO4FCec83e YxzA== X-Gm-Message-State: AOAM5322gYsVwjzTMt57wozlcW4SzUGcxhjXYBtwXuSkoiw/+2cyX6kA abyeZOsXhU29CHUJ+lCJtAF1bKc4n+3Qn/WI0/QB2A== X-Google-Smtp-Source: ABdhPJzxIVeK+L2e+onyoruFbk5PK1574ToAhK5uI3ldOjqqBWc10scrDjIH2jCqLpQpkmENVOjLw/AbjiJEiUPKQXA= X-Received: by 2002:a25:8888:: with SMTP id d8mr31629782ybl.379.1627458860667; Wed, 28 Jul 2021 00:54:20 -0700 (PDT) MIME-Version: 1.0 References: <20210610155811.3313927-1-konstantin@daynix.com> In-Reply-To: From: Konstantin Kostiuk Date: Wed, 28 Jul 2021 10:54:09 +0300 Message-ID: Subject: Re: [PATCH v2] qga-win: Free GMatchInfo properly To: Michael Roth Content-Type: multipart/alternative; boundary="00000000000046e8a705c82a4b20" Received-SPF: none client-ip=2607:f8b0:4864:20::b2b; envelope-from=konstantin@daynix.com; helo=mail-yb1-xb2b.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" --00000000000046e8a705c82a4b20 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ping On Wed, Jul 14, 2021 at 10:26 AM Konstantin Kostiuk wrote: > 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 :| >> >> --00000000000046e8a705c82a4b20 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
ping

On Wed, Jul 14, 2021 at 10:26 AM Konstantin Kostiu= k <konstantin@daynix.com>= ; wrote:
CC Michael Roth

On Thu, Jun 10, 2021 at 7:14 PM Daniel P. Ber= rang=C3=A9 <ber= range@redhat.com> wrote:
On Thu, Jun 10, 2021 at 07:08:36PM +0300, Konstantin Kostiu= k 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 :|

--00000000000046e8a705c82a4b20--