conf: simplify virDomainCapsDispose()

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>
This commit is contained in:
Laine Stump 2021-02-02 01:11:30 -05:00
parent 1745297d51
commit f772c48697

View 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);
}