[PATCH 21/23] Switch away from virHashFree
Peter Krempa
pkrempa at redhat.com
Tue Nov 30 15:18:20 UTC 2021
On Tue, Nov 30, 2021 at 15:14:14 +0000, Daniel P. Berrangé wrote:
> On Tue, Nov 30, 2021 at 03:32:05PM +0100, Peter Krempa wrote:
> > Use 'g_clear_pointer(&ptr, g_hash_table_unref)' instead.
> >
> > In few instances it allows us to also remove explicit clearing of
> > pointers.
> >
> > Signed-off-by: Peter Krempa <pkrempa at redhat.com>
> > ---
> > src/conf/domain_addr.c | 2 +-
> > src/conf/domain_conf.c | 2 +-
> > src/conf/nwfilter_conf.c | 2 +-
> > src/conf/nwfilter_ipaddrmap.c | 3 +--
> > src/conf/virchrdev.c | 2 +-
> > src/conf/virdomainmomentobjlist.c | 2 +-
> > src/conf/virdomainobjlist.c | 4 ++--
> > src/conf/virinterfaceobj.c | 2 +-
> > src/conf/virnetworkobj.c | 4 ++--
> > src/conf/virnodedeviceobj.c | 2 +-
> > src/conf/virnwfilterbindingdef.c | 2 +-
> > src/conf/virnwfilterbindingobjlist.c | 2 +-
> > src/conf/virsecretobj.c | 2 +-
> > src/conf/virstorageobj.c | 10 +++++-----
> > src/hyperv/hyperv_wmi.c | 2 +-
> > src/hypervisor/virclosecallbacks.c | 2 +-
> > src/libxl/libxl_logger.c | 2 +-
> > src/locking/lock_daemon.c | 2 +-
> > src/nwfilter/nwfilter_dhcpsnoop.c | 6 +++---
> > src/nwfilter/nwfilter_gentech_driver.c | 2 +-
> > src/nwfilter/nwfilter_learnipaddr.c | 7 ++-----
> > src/qemu/qemu_domain.c | 2 +-
> > src/qemu/qemu_driver.c | 2 +-
> > src/rpc/virnetdaemon.c | 2 +-
> > src/security/security_selinux.c | 6 +++---
> > src/util/virfilecache.c | 2 +-
> > src/util/virhash.c | 2 +-
> > src/util/virlockspace.c | 2 +-
> > src/util/virmacmap.c | 2 +-
> > src/util/virsystemd.c | 2 +-
> > tests/nwfilterxml2firewalltest.c | 2 +-
> > tests/qemusecuritymock.c | 7 +++----
> > 32 files changed, 45 insertions(+), 50 deletions(-)
> >
> > diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
> > index a06721c35d..49745ba881 100644
> > --- a/src/conf/domain_addr.c
> > +++ b/src/conf/domain_addr.c
> > @@ -1377,7 +1377,7 @@ void virDomainCCWAddressSetFree(virDomainCCWAddressSet *addrs)
> > if (!addrs)
> > return;
> >
> > - virHashFree(addrs->defined);
> > + g_clear_pointer(&addrs->defined, g_hash_table_unref);
>
> This is in a Free() method, so we should just be calling
> g_hash_table_unref directly. Likewise for all the other
g_hash_table_unref requires a valid GHashTable pointer to be passed.
g_clear_pointer ensures that we don't call it while the freed table
would be NULL.
Most Free* methods are also used on cleanup paths when the insides of
the struct may still be NULL and IMO it's not worth analyzing the code
and neither converting to:
if (htptr)
g_hash_table_unref(htptr);
for the instances where setting the variable to NULL is pointless.
More information about the libvir-list
mailing list