[libvirt] [PATCH 05/42] rpc: Don't check the output of virGetUserDirectory()

Pavel Hrdina phrdina at redhat.com
Thu Dec 19 16:44:31 UTC 2019


On Thu, Dec 19, 2019 at 05:42:14PM +0100, Ján Tomko wrote:
> On Thu, Dec 19, 2019 at 05:25:59PM +0100, Pavel Hrdina wrote:
> > On Thu, Dec 19, 2019 at 05:21:21PM +0100, Fabiano Fidêncio wrote:
> > > On Thu, Dec 19, 2019 at 5:07 PM Pavel Hrdina <phrdina at redhat.com> wrote:
> > > >
> > > > On Thu, Dec 19, 2019 at 11:04:10AM +0100, Fabiano Fidêncio wrote:
> > > > > virGetUserDirectory() *never* *ever* returns NULL, making the checks for
> > > > > it completely unnecessary.
> > > > >
> > > > > Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
> > > > > ---
> > > > >  src/rpc/virnetclient.c     | 12 ++++--------
> > > > >  src/rpc/virnettlscontext.c | 12 ------------
> > > > >  2 files changed, 4 insertions(+), 20 deletions(-)
> > > >
> > > > [...]
> > > >
> > > > > diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
> > > > > index ec9dd35c46..08944f6771 100644
> > > > > --- a/src/rpc/virnettlscontext.c
> > > > > +++ b/src/rpc/virnettlscontext.c
> > > > > @@ -805,9 +805,6 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
> > > > >           */
> > > > >          userdir = virGetUserDirectory();
> > > > >
> > > > > -        if (!userdir)
> > > > > -            goto error;
> > > > > -
> > > > >          user_pki_path = g_strdup_printf("%s/.pki/libvirt", userdir);
> > > > >
> > > > >          VIR_DEBUG("Trying to find TLS user credentials in %s", user_pki_path);
> > > > > @@ -864,15 +861,6 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
> > > > >      VIR_FREE(userdir);
> > > > >
> > > > >      return 0;
> > > > > -
> > > > > - error:
> > > > > -    VIR_FREE(*cacert);
> > > > > -    VIR_FREE(*cacrl);
> > > > > -    VIR_FREE(*key);
> > > > > -    VIR_FREE(*cert);
> > > > > -    VIR_FREE(user_pki_path);
> > > > > -    VIR_FREE(userdir);
> > > > > -    return -1;
> > > >
> > > > This doesn't look right.  Looks like some leftover from rebase where
> > > > you wanted to use g_autofree.
> > > 
> > > No, actually not. The only usage of `goto error` was when checking the
> > > result of virGetUserDirectory().
> > > By removing the check, we have also to remove the label.
> > 
> > Label yes, the VIR_FREE no as it would leak the memory.
> > 
> 
> There's "return 0;" right before that label.

Oh, I see, two strings are freed and the remaining ones are
transferred to caller.  Somehow I missed that.

Pavel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20191219/2bfab282/attachment-0001.sig>


More information about the libvir-list mailing list