]> xenbits.xensource.com Git - libvirt.git/commit
virpcivpdtest: Fix potential double-free()
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 28 Jan 2022 19:37:42 +0000 (20:37 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 1 Feb 2022 16:37:06 +0000 (17:37 +0100)
commita7c016e4cb494a55650dafee187f3438f80eeed4
treec626f0e47ddec8891fcb8cc5724cd20783926b52
parentce880ad8ba4894d1fee0df50aa37fca4142ae791
virpcivpdtest: Fix potential double-free()

Inside the testPCIVPDResourceCustomCompareIndex() function we
have two variables @a and @b, both marked as g_autoptr(). Then,
towards the end of the function b->value is freed and set to
a->value. This is to make sure
virPCIVPDResourceCustomCompareIndex() works correctly even if
->value member is the same for both arguments.

Nevertheless, if the function returns anything else than 0 then
the control executes subsequent return statement and since
b->value points to the very same string as a->value a double free
will occur. Avoid this by setting b->value to NULL explicitly,
just like we are already doing for the successful path.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
tests/virpcivpdtest.c