Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 786674 - Plug memory leak on cmdUndefine
Plug memory leak on cmdUndefine
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt (Show other bugs)
6.3
x86_64 Linux
high Severity high
: rc
: ---
Assigned To: Alex Jia
Virtualization Bugs
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-02-02 01:21 EST by Alex Jia
Modified: 2012-06-20 02:47 EDT (History)
8 users (show)

See Also:
Fixed In Version: libvirt-0.9.10-1.el6
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-06-20 02:47:46 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2012:0748 normal SHIPPED_LIVE Low: libvirt security, bug fix, and enhancement update 2012-06-19 15:31:38 EDT

  None (edit)
Description Alex Jia 2012-02-02 01:21:01 EST
Description of problem:
virsh undefine command with '--remove-all-storage' option will plug memory leak.

Version-Release number of selected component (if applicable):
# rpm -q libvirt
libvirt-0.9.9-2.el6.x86_64

How reproducible:
always

Steps to Reproduce:
% dd if=/dev/null of=/var/lib/libvirt/images/foo bs=1 count=1 seek=10M
% virsh define foo.xml                   (disk source file points to '/var/lib/libvirt/images/foo')
% virsh vol-clone foo foo-clone default  (the original guest name is 'foo')
% virsh pool-refresh default
% virsh vol-list default                 (make sure 'foo-clone' volume exists)
% virsh define foo-clone.xml             (disk source file points to '/var/lib/libvirt/images/foo-clone')
% valgrind -v --leak-check=full virsh undefine foo-clone --remove-all-storage
  
Actual results:

1. virsh output
Domain foo-clone has been undefined
Volume '/var/lib/libvirt/images/foo-clone' removed.

error: Failed to disconnect from the hypervisor, 1 leaked reference(s)

2. valgrind result

==6515== 92 (40 direct, 52 indirect) bytes in 1 blocks are definitely lost in loss record 46 of 69
==6515==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==6515==    by 0x4C89B71: virAlloc (memory.c:101)
==6515==    by 0x4CFCACE: virGetStorageVol (datatypes.c:724)
==6515==    by 0x4D4A8E0: remoteStorageVolLookupByPath (remote_driver.c:4664)
==6515==    by 0x4D07153: virStorageVolLookupByPath (libvirt.c:12508)
==6515==    by 0x4270E6: cmdUndefine (virsh.c:2828)
==6515==    by 0x4151B6: vshCommandRun (virsh.c:17693)
==6515==    by 0x4264D3: main (virsh.c:19270)
==6515==
==6515== LEAK SUMMARY:
==6515==    definitely lost: 40 bytes in 1 blocks


Expected results:
fix memory leak.

Additional info:
Comment 1 Peter Krempa 2012-02-02 05:49:56 EST
Fixed upstream with:

commit 6152c74595df3ac0bb4dad083beef842a28d7d0d
Author: Alex Jia <ajia@redhat.com>
Date:   Thu Feb 2 14:25:25 2012 +0800

    virsh: Plug memory leak on cmdUndefine
    
    Detected by valgrind. Leak is introduced in commit 3bb6bcf.
    
    Free 'vol' memory before allocating memory, the codes will miss one time
    free when 'vol_i = nvolumes' in for loop, so plug memory leak.
Comment 4 zhe peng 2012-02-15 01:07:34 EST
I can reproduce this issue with:
libvirt-0.9.9-2.el6.x86_64

verify with:
libvirt-0.9.10-1.el6.x86_64

step:
# dd if=/dev/null of=/var/lib/libvirt/images/foo bs=1 count=1 seek=10M
# virsh define foo.xml                   (disk source file points to
'/var/lib/libvirt/images/foo')
# virsh vol-clone foo foo-clone default  (the original guest name is 'foo')
# virsh pool-refresh default
# virsh vol-list default                 (make sure 'foo-clone' volume exists)
# virsh define foo-clone.xml             (disk source file points to
'/var/lib/libvirt/images/foo-clone')
# valgrind -v --leak-check=full virsh undefine foo-clone --remove-all-storage

virsh output:
Domain foo-clone has been undefined
Volume '/var/lib/libvirt/images/foo-clone' removed.

no leak error display 

valgrind result:
==26328== LEAK SUMMARY:
==26328==    definitely lost: 0 bytes in 0 blocks
==26328==    indirectly lost: 0 bytes in 0 blocks
==26328==      possibly lost: 0 bytes in 0 blocks
==26328==    still reachable: 127,873 bytes in 1,360 blocks
==26328==         suppressed: 0 bytes in 0 blocks
==26328== Reachable blocks (those to which a pointer was found) are not shown.
==26328== To see them, rerun with: --leak-check=full --show-reachable=yes
==26328== 
==26328== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 6)
--26328-- 
--26328-- used_suppression:      8 dl-hack3-cond-1
==26328== 
==26328== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 6)

verification passed.
move to verified.
Comment 6 errata-xmlrpc 2012-06-20 02:47:46 EDT
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

Note You need to log in before you can comment on or make changes to this bug.