util: rename two *Free() functions while changing VIR_FREE to g_free

dhcpHostFree() and addnHostFree() don't follow the normal pattern of
*Free functions in the rest of libvirt code - they are actually more
similar to the *Dispose() functions, in that they free all subordinate
objects, but not the object pointed to by the argument
itself. However, the arguments aren't virObjects, so it wouldn't be
proper to name them *Dispose() either.

They *currently* behave similar to a *Clear() function, in that they
free all the subordinate objects and nullify the pointers of those
objects. HOWEVER, we don't actually need or want that behavior - the
two functions in question are only called as part of a higher level
*Free() function, and the pointers are not referenced in any way
between the time they are freed and when the parent object is freed.

So, since the current name isn't correct, nor is *Dispose(), and we
want to change the behavior in such a way that *Clear() also wouldn't
be correct, lets name the functions *FreeContent(), which is an
accurate description of what the functions do, and what we *want* them
to do.

And since it's such a small patch, we can go ahead and change that
behavior - replacing the VIR_FREEs with g_free.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Laine Stump 2021-02-03 21:38:59 -05:00
parent bb6fa828f9
commit 8626fb378c

View File

@ -50,20 +50,20 @@ VIR_LOG_INIT("util.dnsmasq");
#define DNSMASQ_ADDNHOSTSFILE_SUFFIX "addnhosts"
static void
dhcphostFree(dnsmasqDhcpHost *host)
dhcphostFreeContent(dnsmasqDhcpHost *host)
{
VIR_FREE(host->host);
g_free(host->host);
}
static void
addnhostFree(dnsmasqAddnHost *host)
addnhostFreeContent(dnsmasqAddnHost *host)
{
size_t i;
for (i = 0; i < host->nhostnames; i++)
VIR_FREE(host->hostnames[i]);
VIR_FREE(host->hostnames);
VIR_FREE(host->ip);
g_free(host->hostnames[i]);
g_free(host->hostnames);
g_free(host->ip);
}
static void
@ -73,7 +73,7 @@ addnhostsFree(dnsmasqAddnHostsfile *addnhostsfile)
if (addnhostsfile->hosts) {
for (i = 0; i < addnhostsfile->nhosts; i++)
addnhostFree(&addnhostsfile->hosts[i]);
addnhostFreeContent(&addnhostsfile->hosts[i]);
g_free(addnhostsfile->hosts);
@ -270,7 +270,7 @@ hostsfileFree(dnsmasqHostsfile *hostsfile)
if (hostsfile->hosts) {
for (i = 0; i < hostsfile->nhosts; i++)
dhcphostFree(&hostsfile->hosts[i]);
dhcphostFreeContent(&hostsfile->hosts[i]);
g_free(hostsfile->hosts);