Skip to content

Commit

Permalink
virpci: Resolve leak in virPCIVirtualFunctionList cleanup
Browse files Browse the repository at this point in the history
Repeatedly querying an SR-IOV PCI device's capabilities exposes a
memory leak caused by a failure to free the virPCIVirtualFunction
array within the parent struct's g_autoptr cleanup.

Valgrind output after getting a single interface's XML description
1000 times:

==325982== 256,000 bytes in 1,000 blocks are definitely lost in loss record 2,634 of 2,635
==325982==    at 0x4C3C096: realloc (vg_replace_malloc.c:1437)
==325982==    by 0x59D952D: g_realloc (in /usr/lib64/libglib-2.0.so.0.5600.4)
==325982==    by 0x4EE1F52: virReallocN (viralloc.c:52)
==325982==    by 0x4EE1FB7: virExpandN (viralloc.c:78)
==325982==    by 0x4EE219A: virInsertElementInternal (viralloc.c:183)
==325982==    by 0x4EE23B2: virAppendElement (viralloc.c:288)
==325982==    by 0x4F65D85: virPCIGetVirtualFunctionsFull (virpci.c:2389)
==325982==    by 0x4F65753: virPCIGetVirtualFunctions (virpci.c:2256)
==325982==    by 0x505CB75: virNodeDeviceGetPCISRIOVCaps (node_device_conf.c:2969)
==325982==    by 0x505D181: virNodeDeviceGetPCIDynamicCaps (node_device_conf.c:3099)
==325982==    by 0x505BC4E: virNodeDeviceUpdateCaps (node_device_conf.c:2677)
==325982==    by 0x260FCBB2: nodeDeviceGetXMLDesc (node_device_driver.c:355)

Signed-off-by: Tim Shearer <tshearer@adva.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
  • Loading branch information
kempstonjoystick authored and janotomko committed May 2, 2023
1 parent 844a3b4 commit 6425a31
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/util/virpci.c
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,7 @@ virPCIVirtualFunctionListFree(virPCIVirtualFunctionList *list)
g_free(list->functions[i].ifname);
}

g_free(list->functions);
g_free(list);
}

Expand Down

0 comments on commit 6425a31

Please sign in to comment.