[PATCH] node_device_conf: Don't prealloc @vfs in virNodeDeviceGetPCISRIOVCaps()

Michal Privoznik posted 1 patch 2 years, 7 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/429023dda5213d9415c5f7a8d58e6ad29242d9ed.1631432078.git.mprivozn@redhat.com
src/conf/node_device_conf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] node_device_conf: Don't prealloc @vfs in virNodeDeviceGetPCISRIOVCaps()
Posted by Michal Privoznik 2 years, 7 months ago
The array of virtual functions @vfs in
virNodeDeviceGetPCISRIOVCaps() is allocated twice: the first time
during its declaration and the second time inside
virPCIGetVirtualFunctions() which leads to a memleak:

==16691== 1,128 bytes in 47 blocks are definitely lost in loss record 1,771 of 1,803
==16691==    at 0x4844CC1: calloc (vg_replace_malloc.c:1117)
==16691==    by 0x4E50070: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6800.3)
==16691==    by 0x4A7B034: virNodeDeviceGetPCISRIOVCaps (node_device_conf.c:2649)
==16691==    by 0x4A7B5E2: virNodeDeviceGetPCIDynamicCaps (node_device_conf.c:2762)
==16691==    by 0xA7F6E18: udevProcessPCI (node_device_udev.c:418)

Fixes: c97518d9b833a607f29b9bb02e3fbe74c011c088
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/node_device_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index b4c1acb6a5..9bbff97ffd 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -2646,7 +2646,7 @@ static int
 virNodeDeviceGetPCISRIOVCaps(const char *sysfsPath,
                              virNodeDevCapPCIDev *pci_dev)
 {
-    g_autoptr(virPCIVirtualFunctionList) vfs = g_new0(virPCIVirtualFunctionList, 1);
+    g_autoptr(virPCIVirtualFunctionList) vfs = NULL;
     size_t i;
     int ret;
 
-- 
2.32.0

Re: [PATCH] node_device_conf: Don't prealloc @vfs in virNodeDeviceGetPCISRIOVCaps()
Posted by Ján Tomko 2 years, 7 months ago
On a Sunday in 2021, Michal Privoznik wrote:
>The array of virtual functions @vfs in
>virNodeDeviceGetPCISRIOVCaps() is allocated twice: the first time
>during its declaration and the second time inside
>virPCIGetVirtualFunctions() which leads to a memleak:
>
>==16691== 1,128 bytes in 47 blocks are definitely lost in loss record 1,771 of 1,803
>==16691==    at 0x4844CC1: calloc (vg_replace_malloc.c:1117)
>==16691==    by 0x4E50070: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6800.3)
>==16691==    by 0x4A7B034: virNodeDeviceGetPCISRIOVCaps (node_device_conf.c:2649)
>==16691==    by 0x4A7B5E2: virNodeDeviceGetPCIDynamicCaps (node_device_conf.c:2762)
>==16691==    by 0xA7F6E18: udevProcessPCI (node_device_udev.c:418)
>
>Fixes: c97518d9b833a607f29b9bb02e3fbe74c011c088
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/conf/node_device_conf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano