From 71f0d7c366ee2ac2d6158c7c7ea6c3c2240ebc65 Mon Sep 17 00:00:00 2001 From: Zhiqiang Liu <liuzhiqiang26@huawei.com> Date: Thu, 5 Nov 2020 18:26:18 +0800 Subject: [PATCH] test/test_syscalls.c: fix potential fd leakage problems In test_syscalls.c, several funcs have potential fd leakage problems. This patch will fix them. Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com> Signed-off-by: Haotian Li <lihaotian9@huawei.com> --- test/test_syscalls.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/test_syscalls.c b/test/test_syscalls.c index 18326c0..4fa5c87 100644 --- a/test/test_syscalls.c +++ b/test/test_syscalls.c @@ -779,6 +779,7 @@ static int test_copy_file_range(void) res = close(fd_in); if (res == -1) { PERROR("close"); + close(fd_out); return -1; } res = close(fd_out); @@ -932,8 +933,10 @@ static int test_create_unlink(void) return -1; } res = check_nonexist(testfile); - if (res == -1) + if (res == -1) { + close(fd); return -1; + } res = write(fd, data, datalen); if (res == -1) { PERROR("write"); @@ -1766,8 +1769,10 @@ static int test_socket(void) } res = check_type(testsock, S_IFSOCK); - if (res == -1) + if (res == -1) { + close(fd); return -1; + } err += check_nlink(testsock, 1); close(fd); res = unlink(testsock); -- 2.30.2