On 11/11/26 9:17 AM, Boris Fiuczynski wrote:
As the fallthrough of this method is return VIR_CPU_COMPARE_ERROR this
can potentially result in returning the error and have allocated
memory for responsibleProps.
Using g_auto(GStrv) props = NULL; and steal it before finally
returning would prevent this. e.g.
...
g_auto(GStrv) props = NULL;
virCPUCompareResult ret;
...
if (responsibleProps && propsArray &&
virJSONValueArraySize(propsArray) > 0 &&
!(props = virJSONValueArrayToStringList(propsArray))) {
return VIR_CPU_COMPARE_ERROR;
}
if (STREQ(result, "identical")) {
ret = VIR_CPU_COMPARE_IDENTICAL;
} else if (STREQ(result, "superset")) {
ret = VIR_CPU_COMPARE_SUPERSET;
} else if (STREQ(result, "subset") || STREQ(result,
"incompatible")) {
ret = VIR_CPU_COMPARE_INCOMPATIBLE;
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown query-cpu-model-comparison result:
'%1$s'"),
result);
return VIR_CPU_COMPARE_ERROR;
}
if (responsibleProps)
*responsibleProps = g_steal_pointer(&props);
return ret;
}
Thanks Boris, good catch. I will apply the above to ensure we don't leak
memory on error paths.