Bug 786674 - Plug memory leak on cmdUndefine
Summary: Plug memory leak on cmdUndefine
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt
Version: 6.3
Hardware: x86_64
OS: Linux
high
high
Target Milestone: rc
: ---
Assignee: Alex Jia
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-02-02 06:21 UTC by Alex Jia
Modified: 2012-06-20 06:47 UTC (History)
8 users (show)

Fixed In Version: libvirt-0.9.10-1.el6
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-06-20 06:47:46 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2012:0748 0 normal SHIPPED_LIVE Low: libvirt security, bug fix, and enhancement update 2012-06-19 19:31:38 UTC

Description Alex Jia 2012-02-02 06:21:01 UTC
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 10:49:56 UTC
Fixed upstream with:

commit 6152c74595df3ac0bb4dad083beef842a28d7d0d
Author: Alex Jia <ajia>
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 06:07:34 UTC
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 06:47:46 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


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