On Thu, Nov 12, 2026 at 03:57:20 -0500, Rorie Reyes wrote:
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.
We wouldn't really leak anything as the caller will free the memory anyway. But this approach is definitely better. Jirka