Project

General

Profile

Bug #5494

libndmp memory leaks when setting a property

Added by Jan Kryl almost 6 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
lib - userland libraries
Start date:
2014-12-29
Due date:
% Done:

100%

Estimated time:
Difficulty:
Bite-size
Tags:
Gerrit CR:

Description

libumem discovered following memory leaks in libndmp when setting NDMP property:

umem_alloc_16 leak: 2 buffers, 16 bytes each, 32 bytes total
            ADDR          BUFADDR        TIMESTAMP           THREAD
                            CACHE          LASTLOG         CONTENTS
         8f135c8          8f109e0   1ab5d260512cf5                6
                          8ef5290                0                0
                 libumem.so.1`umem_cache_alloc_debug+0x1fe
                 libumem.so.1`umem_cache_alloc+0x99
                 libumem.so.1`umem_alloc+0x50
                 libumem.so.1`umem_malloc+0x36
                 libc_hwcap1.so.1`strdup+0x2e
                 libscf.so.1`smf_get_state+0x69
                 libndmp.so.1`ndmp_service_refresh+0x1f
                 ndmp.node`_ZN4ndmp13EnableAuthJob8beginJobEv+0x380
                 ndmp.node`_ZN3nef8AsyncJob10onBeginJobEP9uv_work_s+0x2c
                 worker+0x77
                 uv__thread_start+0x1d
                 libc_hwcap1.so.1`_thrp_setup+0x88
                 libc_hwcap1.so.1`_lwp_start

umem_alloc_32 leak: 1 buffer, 32 bytes
            ADDR          BUFADDR        TIMESTAMP           THREAD
                            CACHE          LASTLOG         CONTENTS
         9145698          9143ca0   1ab5d25be11282                6
                          8ef5790                0                0
                 libumem.so.1`umem_cache_alloc_debug+0x1fe
                 libumem.so.1`umem_cache_alloc+0x99
                 libumem.so.1`umem_alloc+0x50
                 libumem.so.1`umem_malloc+0x36
                 libuutil.so.1`uu_zalloc+0x1e
                 libscf.so.1`scf_snapshot_create+0x1b
                 libscf.so.1`scf_handle_create+0x189
                 libndmp.so.1`ndmp_smf_scf_init+0x3b
                 libndmp.so.1`ndmp_set_prop+0x24
                 ndmp.node`_ZN4ndmp13EnableAuthJob8beginJobEv+0x3f
                 ndmp.node`_ZN3nef8AsyncJob10onBeginJobEP9uv_work_s+0x2c
                 worker+0x77
                 uv__thread_start+0x1d
                 libc_hwcap1.so.1`_thrp_setup+0x88
                 libc_hwcap1.so.1`_lwp_start

The first one was easy to find and fix. Eliminating useless call to smf_get_state() in ndmp_service_refresh() fixes it.

The second one was more difficult to find. scf handle which is used for getting/setting SMF properties was leaked because one of the references to it wasn't properly released. The leaked reference belongs to "property" object allocated in ndmp_smf_set_property() (call to scf_property_create()), which isn't properly destroyed by calling scf_property_destroy(). Furthermore the code in ndmp_smf_set_property is badly structured which is the reason why the leak wasn't apparent. I took this opportunity to restructure it in better way.

There are also a couple of apparent memory leaks in error paths which are going to be fixed too on behalf of this ticket.

History

#1

Updated by Electric Monk almost 6 years ago

  • Status changed from In Progress to Closed

git commit f093add7b63e274f746dd55365f052cded44cc16

commit  f093add7b63e274f746dd55365f052cded44cc16
Author: Jan Kryl <jan.kryl@nexenta.com>
Date:   2015-01-08T18:05:15.000Z

    5494 libndmp memory leaks when setting a property
    Reviewed by: Dan Fields <dan.fields@nexenta.com>
    Approved by: Gordon Ross <gwr@nexenta.com>

Also available in: Atom PDF