[PATCH mptcp-next v2 2/2] selftests: mptcp: close fds when copyfd_io fails

Geliang Tang posted 2 patches 3 weeks, 2 days ago
There is a newer version of this series
[PATCH mptcp-next v2 2/2] selftests: mptcp: close fds when copyfd_io fails
Posted by Geliang Tang 3 weeks, 2 days ago
From: Geliang Tang <tanggeliang@kylinos.cn>

When copyfd_io fails, it should not simply return an error, but should
close all open file descriptors before that. Here an "out" tag is added
to do this.

Fixes: 05be5e273c84 ("selftests: mptcp: add disconnect tests")
Co-developed-by: Cong Liu <liucong2@kylinos.cn>
Signed-off-by: Cong Liu <liucong2@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/mptcp_connect.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index 5301062a5f3b..f190f95a3338 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -1293,7 +1293,7 @@ int main_loop(void)
 
 	ret = copyfd_io(fd_in, fd, 1, 0, &winfo);
 	if (ret)
-		return ret;
+		goto out;
 
 	if (cfg_truncate > 0) {
 		shutdown(fd, SHUT_WR);
@@ -1309,12 +1309,13 @@ int main_loop(void)
 		memset(&winfo, 0, sizeof(winfo));
 		goto again;
 	} else {
+out:
 		close(fd);
 	}
 
 	if (cfg_input)
 		close(fd_in);
-	return 0;
+	return ret;
 }
 
 int parse_proto(const char *proto)
-- 
2.43.0