Bug 761453

Summary: memory leak on remoteDomainScreenshot function
Product: Red Hat Enterprise Linux 6 Reporter: Alex Jia <ajia>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: high Docs Contact:
Priority: high    
Version: 6.3CC: acathrow, dallan, dyuan, mshao, mzhan, rwu, zhpeng
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-0.9.9-1.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-06-20 06:38:22 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Alex Jia 2011-12-08 11:09:33 UTC
Description of problem:
Plug memory leak on remoteDomainScreenshot function.

Version-Release number of selected component (if applicable):
libvirt-0.9.8-0rc2.el6.x86_64

How reproducible:
always

Steps to Reproduce:
1. start a guest
2. valgrind -v --leak-check=full virsh screenshot <guest name>
  
Actual results:

==17665== 24 bytes in 1 blocks are definitely lost in loss record 4 of 28
==17665==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==17665==    by 0x321FB1497D: xdr_string (in /lib64/libc-2.12.so)
==17665==    by 0x3238AFA2AD: xdr_remote_nonnull_string (remote_protocol.c:30)
==17665==    by 0x321FB15F4F: xdr_reference (in /lib64/libc-2.12.so)
==17665==    by 0x321FB15F10: xdr_pointer (in /lib64/libc-2.12.so)
==17665==    by 0x3238AF9E04: xdr_remote_string (remote_protocol.c:39)
==17665==    by 0x3238AFA068: xdr_remote_domain_screenshot_ret (remote_protocol.c:1398)
==17665==    by 0x3238B09EB2: virNetMessageDecodePayload (virnetmessage.c:382)
==17665==    by 0x3238B023FC: virNetClientProgramCall (virnetclientprogram.c:382)
==17665==    by 0x3238AE34BD: callWithFD (remote_driver.c:4333)
==17665==    by 0x3238AE353B: call (remote_driver.c:4354)
==17665==    by 0x3238AF5410: remoteDomainScreenshot (remote_client_bodies.h:1839)
==17665==
==17665== LEAK SUMMARY:
==17665==    definitely lost: 24 bytes in 1 blocks
==17665==    indirectly lost: 0 bytes in 0 blocks
==17665==      possibly lost: 0 bytes in 0 blocks
==17665==    still reachable: 126,936 bytes in 1,340 blocks

Expected results:
avoid memory leak.

Additional info:

Should add 'xdr_free((xdrproc_t)xdr_remote_domain_screenshot_ret, (char *)&ret)' to free allocated memory, it needs to change src/rpc/gendispatch.pl,
I'm not familiar with this.

Comment 1 Michal Privoznik 2011-12-12 15:56:37 UTC
Actually, as we want to keep return value of call(remote_driver.c:4354) and pass it to caller, we don't want to free it completely.

Moreover, the documentation to virDomainScreenshot() says, caller MUST free return value (=mime type of screenshot). And virsh was not doing that. However, was fixed:

commit 0fe2b40d5a1858f7eb0d42f46393e566b6d60812
Author:     Michal Privoznik <mprivozn>
AuthorDate: Mon Dec 12 15:57:28 2011 +0100
Commit:     Michal Privoznik <mprivozn>
CommitDate: Mon Dec 12 15:57:28 2011 +0100

    virsh: Free returned MIME type string
    
    In terms of documentation to virDomainScreenshot, caller MUST free
    returned value. But virsh was not.


Therefore moving to POST.

Comment 3 zhpeng 2011-12-13 10:11:01 UTC
I can reproduce this with libvirt-0.9.8-1.el6.x86_64

Comment 5 xhu 2012-01-10 08:25:54 UTC
Reproduce it with libvirt-0.9.8-0rc2.el6.x86_64.
Verify it with libvirt-0.9.9-1.el6 and it passed.

Comment 7 errata-xmlrpc 2012-06-20 06:38:22 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.

http://rhn.redhat.com/errata/RHSA-2012-0748.html