diff options
author | liaoyuxiangqin <[email protected]> | 2016-07-30 11:03:01 +0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2016-08-01 12:49:03 -0700 |
commit | e24e62a948e1519fb4c1bfc40d9d51e36fbbe63e (patch) | |
tree | a29f9fe24fdbe2c727b8212f0940ae3f5cd9f924 /lib | |
parent | df053d67a9c07a9763a4c04468083644eb9aa234 (diff) |
Fix memory leak in function add_config()
Config of a hot spare or l2cache device will leak memory in function
add_config(). At the start of this function, when dealing with a
config which belongs to a hot spare not currently in use or a l2cache
device the config should be freed.
Signed-off-by: liaoyuxiangqin <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #4910
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libzfs/libzfs_import.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/libzfs/libzfs_import.c b/lib/libzfs/libzfs_import.c index fb3525848..edc0adcee 100644 --- a/lib/libzfs/libzfs_import.c +++ b/lib/libzfs/libzfs_import.c @@ -641,11 +641,14 @@ add_config(libzfs_handle_t *hdl, pool_list_t *pl, const char *path, &state) == 0 && (state == POOL_STATE_SPARE || state == POOL_STATE_L2CACHE) && nvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID, &vdev_guid) == 0) { - if ((ne = zfs_alloc(hdl, sizeof (name_entry_t))) == NULL) + if ((ne = zfs_alloc(hdl, sizeof (name_entry_t))) == NULL) { + nvlist_free(config); return (-1); + } if ((ne->ne_name = zfs_strdup(hdl, path)) == NULL) { free(ne); + nvlist_free(config); return (-1); } ne->ne_guid = vdev_guid; @@ -653,6 +656,7 @@ add_config(libzfs_handle_t *hdl, pool_list_t *pl, const char *path, ne->ne_num_labels = num_labels; ne->ne_next = pl->names; pl->names = ne; + nvlist_free(config); return (0); } |