From: Daniel P. Berrangé <[email protected]> The listener FD passed into qtest_socket_accept should be considered owned by the caller, and thus is is inappropriate and unusual to close it in the method.
Signed-off-by: Daniel P. Berrangé <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> Signed-off-by: Fabiano Rosas <[email protected]> --- tests/qtest/libqtest.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index dcce889ccc1..7f66c1bbb3b 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -132,7 +132,6 @@ static int qtest_socket_accept(QTestState *s, int sock) (void *)&timeout, sizeof(timeout))) { fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n", __func__, strerror(errno)); - close(sock); return -1; } @@ -140,7 +139,7 @@ static int qtest_socket_accept(QTestState *s, int sock) if (!qtest_probe_child(s)) { fprintf(stderr, "child process unexpectedly exited, skipping socket accept\n"); - goto cleanup; + return -1; } addrlen = sizeof(addr); @@ -154,9 +153,6 @@ static int qtest_socket_accept(QTestState *s, int sock) fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno)); } - cleanup: - close(sock); - return ret; } @@ -562,6 +558,8 @@ void qtest_connect(QTestState *s) unlink(socket_path); unlink(qmp_socket_path); g_assert(s->fd >= 0 && s->qmp_fd >= 0); + close(s->sock); + close(s->qmpsock); s->sock = s->qmpsock = -1; /* ask endianness of the target */ s->big_endian = qtest_query_target_endianness(s); @@ -671,6 +669,7 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd) *sock_fd = qtest_socket_accept(qts, sock_fd_init); + close(sock_fd_init); unlink(sock_path); g_free(sock_path); rmdir(sock_dir); -- 2.53.0
