[libvirt] [PATCH 1/6] qemuBuildSCSIiSCSIHostdevDrvStr: Don't leak @netsource and @srcprops

Michal Privoznik posted 6 patches 7 years, 7 months ago
[libvirt] [PATCH 1/6] qemuBuildSCSIiSCSIHostdevDrvStr: Don't leak @netsource and @srcprops
Posted by Michal Privoznik 7 years, 7 months ago
After 6b770f9a3bdabb1 both @netsource and @srcprops are leaked
because of early return introduced in the commit.

==1812== 644 bytes in 4 blocks are definitely lost in loss record 835 of 885
==1812==    at 0x4C2F12F: realloc (vg_replace_malloc.c:785)
==1812==    by 0x8846393: xmlSaveUriRealloc (in /usr/lib64/libxml2.so.2.9.8)
==1812==    by 0x8846B1C: xmlSaveUri (in /usr/lib64/libxml2.so.2.9.8)
==1812==    by 0x5DDA619: virURIFormat (viruri.c:256)
==1812==    by 0x56E941B: qemuBuildNetworkDriveURI (qemu_command.c:781)
==1812==    by 0x56E979A: qemuBuildNetworkDriveStr (qemu_command.c:859)
==1812==    by 0x56F3A0B: qemuBuildSCSIiSCSIHostdevDrvStr (qemu_command.c:4664)
==1812==    by 0x56F3D1F: qemuBuildSCSIHostdevDrvStr (qemu_command.c:4732)
==1812==    by 0x56F57F7: qemuBuildHostdevCommandLine (qemu_command.c:5337)
==1812==    by 0x570303A: qemuBuildCommandLine (qemu_command.c:10376)
==1812==    by 0x57604EE: qemuProcessCreatePretendCmd (qemu_process.c:6649)
==1812==    by 0x11352A: testCompareXMLToArgv (qemuxml2argvtest.c:566)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_command.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 32eb59b6ab..86970f3d91 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4644,8 +4644,8 @@ static char *
 qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
                                 virQEMUCapsPtr qemuCaps)
 {
+    char *ret = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
-
     char *netsource = NULL;
     virJSONValuePtr srcprops = NULL;
     virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
@@ -4672,13 +4672,13 @@ qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
     if (virBufferCheckError(&buf) < 0)
         goto cleanup;
 
-    return virBufferContentAndReset(&buf);
+    ret = virBufferContentAndReset(&buf);
 
  cleanup:
     VIR_FREE(netsource);
     virJSONValueFree(srcprops);
     virBufferFreeAndReset(&buf);
-    return NULL;
+    return ret;
 }
 
 char *
-- 
2.16.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/6] qemuBuildSCSIiSCSIHostdevDrvStr: Don't leak @netsource and @srcprops
Posted by Peter Krempa 7 years, 7 months ago
On Mon, Jul 09, 2018 at 11:56:09 +0200, Michal Privoznik wrote:
> After 6b770f9a3bdabb1 both @netsource and @srcprops are leaked
> because of early return introduced in the commit.

I'd revert this commit completely. The change seems pointless to me.

> 
> ==1812== 644 bytes in 4 blocks are definitely lost in loss record 835 of 885
> ==1812==    at 0x4C2F12F: realloc (vg_replace_malloc.c:785)
> ==1812==    by 0x8846393: xmlSaveUriRealloc (in /usr/lib64/libxml2.so.2.9.8)
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/6] qemuBuildSCSIiSCSIHostdevDrvStr: Don't leak @netsource and @srcprops
Posted by Peter Krempa 7 years, 7 months ago
On Mon, Jul 09, 2018 at 12:54:41 +0200, Peter Krempa wrote:
> On Mon, Jul 09, 2018 at 11:56:09 +0200, Michal Privoznik wrote:
> > After 6b770f9a3bdabb1 both @netsource and @srcprops are leaked
> > because of early return introduced in the commit.
> 
> I'd revert this commit completely. The change seems pointless to me.

Oh, disregard this. The comit seems pointless but is a preparation for a
bugfix.

> 
> > 
> > ==1812== 644 bytes in 4 blocks are definitely lost in loss record 835 of 885
> > ==1812==    at 0x4C2F12F: realloc (vg_replace_malloc.c:785)
> > ==1812==    by 0x8846393: xmlSaveUriRealloc (in /usr/lib64/libxml2.so.2.9.8)

ACK to this patch then.


> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list