From 06cf4d989058a65f72b140d85e2c21effd3b3834 Mon Sep 17 00:00:00 2001 From: cao Date: Thu, 13 Oct 2016 02:16:47 +0800 Subject: [PATCH] Fix coverity defects: CID 147606, 147609 coverity scan CID:147606, Type:resource leak coverity scan CID:147609, Type:resource leak Reviewed-by: Brian Behlendorf Signed-off-by: cao.xuewen Closes #5245 --- cmd/ztest/ztest.c | 5 ++++- lib/libzfs/libzfs_pool.c | 2 +- tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/ztest/ztest.c b/cmd/ztest/ztest.c index 1491e87344..2e4dae3a95 100644 --- a/cmd/ztest/ztest.c +++ b/cmd/ztest/ztest.c @@ -6281,8 +6281,11 @@ ztest_run(ztest_shared_t *zs) kthread_t *thread; if (t < ztest_opts.zo_datasets && - ztest_dataset_open(t) != 0) + ztest_dataset_open(t) != 0) { + umem_free(tid, + ztest_opts.zo_threads * sizeof (kt_did_t)); return; + } VERIFY3P(thread = zk_thread_create(NULL, 0, (thread_func_t)ztest_thread, diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index 1122216747..68cc5f3ee0 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -4159,7 +4159,7 @@ zpool_label_name(char *label_name, int label_size) int fd; fd = open("/dev/urandom", O_RDONLY); - if (fd > 0) { + if (fd >= 0) { if (read(fd, &id, sizeof (id)) != sizeof (id)) id = 0; diff --git a/tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c b/tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c index 3e075e3d70..64348549d9 100644 --- a/tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c +++ b/tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c @@ -108,6 +108,7 @@ main(int argc, char **argv) } j++; } + (void) close(fd); } else if (pid == 0) { int fd = open(dirpath, O_RDONLY); int chownret; @@ -128,6 +129,7 @@ main(int argc, char **argv) k++; } + (void) close(fd); } return (0);