]> granicus.if.org Git - zfs/commitdiff
Fix memory/fd leak in check_file() and is_spare()
authorliuhuang <liu.huang@zte.com.cn>
Sat, 10 Sep 2016 20:41:19 +0000 (04:41 +0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 12 Sep 2016 16:44:26 +0000 (09:44 -0700)
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: liuhuang <liu.huang@zte.com.cn>
Closes #5085

cmd/zpool/zpool_vdev.c

index 7ad44a948c43116dfce0db7e3c761df10e0eff8e..7d114889f5f97e7a35cd49c6f9e8270902f958d2 100644 (file)
@@ -334,8 +334,11 @@ check_file(const char *file, boolean_t force, boolean_t isspare)
                /*
                 * Allow hot spares to be shared between pools.
                 */
-               if (state == POOL_STATE_SPARE && isspare)
+               if (state == POOL_STATE_SPARE && isspare) {
+                       free(name);
+                       (void) close(fd);
                        return (0);
+               }
 
                if (state == POOL_STATE_ACTIVE ||
                    state == POOL_STATE_SPARE || !force) {
@@ -583,8 +586,10 @@ is_spare(nvlist_t *config, const char *path)
        free(name);
        (void) close(fd);
 
-       if (config == NULL)
+       if (config == NULL) {
+               nvlist_free(label);
                return (B_TRUE);
+       }
 
        verify(nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &guid) == 0);
        nvlist_free(label);