Bug 1325043

Summary: libvirt forget free priv->machineName when clear guest resource
Product: Red Hat Enterprise Linux 7 Reporter: Luyao Huang <lhuang>
Component: libvirtAssignee: Martin Kletzander <mkletzan>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.3CC: pzhang, rbalakri
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.3.4-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-03 18:41:23 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Luyao Huang 2016-04-08 03:33:45 UTC
Description of problem:
libvirt forget free priv->machineName when clear guest resource

Version-Release number of selected component (if applicable):
libvirt-1.3.3-1.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. setup valgrind 

# valgrind --leak-check=full libvirtd

2. start guest but fail:

# virsh start rhel7.0-rhel
error: Failed to start domain rhel7.0-rhel
error: internal error: process exited while connecting to monitor: 2016-04-08T03:30:30.832952Z qemu-kvm: -object memory-backend-file,id=ram-node0,prealloc=yes,mem-path=/dev/hugepages1G/libvirt/qemu,size=1053818880: memory size 0x3ed00000 must be equal to or larger than huge page size 0x40000000


3. valgrind info

==31007== 3,300 bytes in 3 blocks are definitely lost in loss record 690 of 704
==31007==    at 0x4C29BFD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==31007==    by 0x4C2BACB: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==31007==    by 0x54ABDBF: virReallocN (viralloc.c:245)
==31007==    by 0x54AE993: virBufferGrow (virbuffer.c:130)
==31007==    by 0x54AEE4A: virBufferVasprintf (virbuffer.c:388)
==31007==    by 0x54AEFD3: virBufferAsprintf (virbuffer.c:361)
==31007==    by 0x550FAE3: virSystemdMakeMachineName (virsystemd.c:161)
==31007==    by 0x1E646623: qemuInitCgroup (qemu_cgroup.c:822)
==31007==    by 0x1E646623: qemuSetupCgroup (qemu_cgroup.c:979)
==31007==    by 0x1E65EA31: qemuProcessLaunch (qemu_process.c:5311)
==31007==    by 0x1E6627C1: qemuProcessStart (qemu_process.c:5570)
==31007==    by 0x1E6BF147: qemuDomainObjStart.constprop.47 (qemu_driver.c:7195)
==31007==    by 0x1E6BF885: qemuDomainCreateWithFlags (qemu_driver.c:7249)


Actual results:

memleak on priv->machineName

Expected results:

no memleak

Additional info:

Comment 1 Martin Kletzander 2016-04-11 12:27:47 UTC
Fixed upstream with v1.3.3-53-g16b41728b59a:

commit 16b41728b59a7188f643937303e3aec4c299a980
Author: Martin Kletzander <mkletzan>
Date:   Fri Apr 8 15:29:40 2016 +0200

    qemu: Free priv->machineName

Comment 3 Luyao Huang 2016-08-09 08:46:39 UTC
Verify this bug with libvirt-2.0.0-4.el7.x86_64:

1. setup valgrind 

# valgrind --leak-check=full libvirtd

2. start guest but fail:

# virsh start r7
error: Failed to start domain r7
error: internal error: process exited while connecting to monitor: 2016-08-09T08:37:15.133793Z qemu-kvm: -object memory-backend-file,id=ram-node1,prealloc=yes,mem-path=/dev/hugepages1G/libvirt/qemu,size=536870912,host-nodes=0-1,policy=bind: memory size 0x20000000 must be equal to or larger than page size 0x40000000

3. check valgrind report, although there is another memory leak in this report, it will be another problem

^C==4306== 
==4306== HEAP SUMMARY:
==4306==     in use at exit: 522,939 bytes in 6,202 blocks
==4306==   total heap usage: 116,468 allocs, 110,266 frees, 180,424,060 bytes allocated
==4306== 
==4306== 48 bytes in 1 blocks are definitely lost in loss record 420 of 642
==4306==    at 0x4C29975: calloc (vg_replace_malloc.c:711)
==4306==    by 0x54B118C: virAllocN (viralloc.c:191)
==4306==    by 0x552E12A: virDomainUSBAddressHubNew (domain_addr.c:1384)
==4306==    by 0x5530C34: virDomainUSBAddressSetAddController (domain_addr.c:1422)
==4306==    by 0x5530C34: virDomainUSBAddressSetAddControllers (domain_addr.c:1547)
==4306==    by 0x21FFCE39: qemuDomainAssignUSBAddresses (qemu_domain_address.c:1741)
==4306==    by 0x21FFCE39: qemuDomainAssignAddresses (qemu_domain_address.c:1791)
==4306==    by 0x22012FA5: qemuProcessPrepareDomain (qemu_process.c:4885)
==4306==    by 0x2201A2DF: qemuProcessStart (qemu_process.c:5460)
==4306==    by 0x220761E7: qemuDomainObjStart.constprop.48 (qemu_driver.c:7059)
==4306==    by 0x22076925: qemuDomainCreateWithFlags (qemu_driver.c:7113)
==4306==    by 0x55C3E3B: virDomainCreate (libvirt-domain.c:6787)
==4306==    by 0x14AF7A: remoteDispatchDomainCreate (remote_dispatch.h:4116)
==4306==    by 0x14AF7A: remoteDispatchDomainCreateHelper (remote_dispatch.h:4092)
==4306==    by 0x562F931: virNetServerProgramDispatchCall (virnetserverprogram.c:437)
==4306==    by 0x562F931: virNetServerProgramDispatch (virnetserverprogram.c:307)
==4306== 
==4306== LEAK SUMMARY:
==4306==    definitely lost: 48 bytes in 1 blocks
==4306==    indirectly lost: 0 bytes in 0 blocks
==4306==      possibly lost: 0 bytes in 0 blocks
==4306==    still reachable: 522,891 bytes in 6,201 blocks
==4306==         suppressed: 0 bytes in 0 blocks
==4306== Reachable blocks (those to which a pointer was found) are not shown.
==4306== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==4306== 
==4306== For counts of detected and suppressed errors, rerun with: -v
==4306== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Comment 5 errata-xmlrpc 2016-11-03 18:41:23 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHSA-2016-2577.html