nwfilter: Avoid possible double free in virNWFilterInstReset()

virNWFilterInstReset() may be called multiple times, leading to a double g_free()
Replace plain g_free() with g_clear_pointer() to prevent this

Found by Linux Verification Center (linuxtesting.org) with Svace.

Reported-by: Dmitry Fedin <d.fedin@fobos-nt.ru>
Signed-off-by: Alexander Kuznetsov <kuznetsovam@altlinux.org>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Alexander Kuznetsov authored and Michal Privoznik committed 2025-04-15 12:57:07 +02:00
1 parent 9ccd9676a8
commit 5de27c32a1
1 file changed
+2 -2
+2 -2
View File
@@ -203,12 +203,12 @@ virNWFilterInstReset(virNWFilterInst *inst)
for (i = 0; i < inst->nfilters; i++)
virNWFilterObjUnlock(inst->filters[i]);
g_free(inst->filters);
g_clear_pointer(inst->filters, g_free);
inst->nfilters = 0;
for (i = 0; i < inst->nrules; i++)
virNWFilterRuleInstFree(inst->rules[i]);
g_free(inst->rules);
g_clear_pointer(inst->rules, g_free);
inst->nrules = 0;
}