]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: simplify virDomainCapsDispose()
authorLaine Stump <laine@redhat.com>
Tue, 2 Feb 2021 06:11:30 +0000 (01:11 -0500)
committerLaine Stump <laine@redhat.com>
Fri, 5 Feb 2021 05:22:09 +0000 (00:22 -0500)
virDomainCapsDispose() was the only caller of
virDomainCapsStringValuesFree(), which 1) didn't actually free the
object it was called with, but only cleared it, making it less
mechanical to convert from VIR_FREE to g_free (since it's not
immediately obvious from looking at virDomainCapsStringValuesFree()
that the pointers being cleared will never again be used).

We could have renamed the function to virDomainCapsStringValuesClear()
to side-step the confusion of what the function actually does, but
that would just make the upcoming switch from VIR_FREE to g_free
require more thought. But since there is only a single caller to the
function, and it is a vir*Dispose() function (indicating that the
object containing the virDomainCapsStringValues is going to be freed
immediately after the function finishes), and thus VIR_FREE() *could*
be safely replaced by g_free()), we instead just move the contents of
virDomainCapsStringValuesFree() into virDomainCapsDispose() (and
*that* function will be trivially converted in an upcoming
"mechanical" patch).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/conf/domain_capabilities.c

index 837c571b45035f942de87689b283133326f17ca7..407cf0348a8348cf91b8a81ae47d68d0c7553b8b 100644 (file)
@@ -65,20 +65,6 @@ static int virDomainCapsOnceInit(void)
 VIR_ONCE_GLOBAL_INIT(virDomainCaps);
 
 
-static void
-virDomainCapsStringValuesFree(virDomainCapsStringValuesPtr values)
-{
-    size_t i;
-
-    if (!values || !values->values)
-        return;
-
-    for (i = 0; i < values->nvalues; i++)
-        VIR_FREE(values->values[i]);
-    VIR_FREE(values->values);
-}
-
-
 void
 virSEVCapabilitiesFree(virSEVCapability *cap)
 {
@@ -95,6 +81,8 @@ static void
 virDomainCapsDispose(void *obj)
 {
     virDomainCapsPtr caps = obj;
+    virDomainCapsStringValuesPtr values;
+    size_t i;
 
     VIR_FREE(caps->path);
     VIR_FREE(caps->machine);
@@ -102,7 +90,10 @@ virDomainCapsDispose(void *obj)
     virCPUDefFree(caps->cpu.hostModel);
     virSEVCapabilitiesFree(caps->sev);
 
-    virDomainCapsStringValuesFree(&caps->os.loader.values);
+    values = &caps->os.loader.values;
+    for (i = 0; i < values->nvalues; i++)
+        VIR_FREE(values->values[i]);
+    VIR_FREE(values->values);
 }