]> granicus.if.org Git - zfs/commitdiff
Fix memory leak in function add_config()
authorliaoyuxiangqin <guo.yong33@zte.com.cn>
Sat, 30 Jul 2016 03:03:01 +0000 (11:03 +0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 1 Aug 2016 19:49:03 +0000 (12:49 -0700)
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 <guo.yong33@zte.com.cn>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4910

lib/libzfs/libzfs_import.c

index fb3525848c9449326ebae2dad169084d18c4ac44..edc0adceec4be017c884227160806703bc3250ad 100644 (file)
@@ -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);
        }