Skip to content

Memory leak in the error handling path #2

Description

@dsvgithub

If VolumeGroup() is instantiated with the name of a non-existent volume, it leaks handles.

I stumbled on this when the volume group I expected to be present has been deleted.

Volume group "localGroup" not found
Failed to initialize VG Handle.
You have a memory leak (not released memory pool):
[0xf52270] library
[0xdd8a00] config
[0xf52960] config
[0xdd88d0] dev_cache
[0xf51f30] command
[0xf52030] format1_orphan
[0xf520a0] format_instance
[0xf57c80] pool_orphan
[0xf57d80] format_instance
[0xf57ee0] text_orphan
[0xf7a5c0] format_instance
[0xef7f20] sysfs
[0xf51ee0] filter regex
Internal error: Unreleased memory pool(s) found.

I found that this got fixed when I made the following code change (call handle.close() before raising the exception):
sudo diff -u /usr/local/lib/python2.7/dist-packages/lvm2py/vg.py.1 /usr/local/lib/python2.7/dist-packages/lvm2py/vg.py
--- /usr/local/lib/python2.7/dist-packages/lvm2py/vg.py.1 2014-07-14 21:18:25.557100681 -0700
+++ /usr/local/lib/python2.7/dist-packages/lvm2py/vg.py 2014-07-14 21:18:36.837100285 -0700
@@ -57,10 +57,12 @@
handle.open()
vgh = lvm_vg_open(handle.handle, name, mode)
if not bool(vgh):

  •        handle.close()
         raise HandleError("Failed to initialize VG Handle.")
     # Close the handle so we can proceed
     cl = lvm_vg_close(vgh)
     if cl != 0:
    
  •        handle.close()
         raise HandleError("Failed to close VG handle after init check.")
     handle.close()
    

With this change, I see the following error only:
Volume group "localGroup" not found
Failed to initialize VG Handle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions