[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] don't leak a file descriptor on failed pciGetDevice call



On Tue, Mar 03, 2009 at 11:13:40AM +0100, Jim Meyering wrote:
> This loop would mistakenly return early (skipping the closedir)
> upon pciGetDevice failure.
> 
> >From 2d4d1d25edf8f1c3f4770707215bba67d73fd59f Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering redhat com>
> Date: Tue, 3 Mar 2009 11:11:07 +0100
> Subject: [PATCH] don't leak a file descriptor on failed pciGetDevice call

ACK, but...

> @@ -823,7 +827,7 @@ void
>  pciFreeDevice(virConnectPtr conn ATTRIBUTE_UNUSED, pciDevice *dev)
>  {
>      VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
> -    if (dev->fd)
> +    if (dev->fd >= 0)
>          close(dev->fd);
>      VIR_FREE(dev);
>  }

With this change you also need to fix the bug in pciGetDevice() which
leaves 'fd' initialized to 0 rather than setting it to -1

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]