From 94dbb7f27f34656ea8a4caa8a3085f69fe7ba5ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 19 Jul 2021 17:21:17 -0400 Subject: [PATCH] Tests fix: unix socket: leaked socket of connection to child MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The child_connection socket is only used by the parent in the credentials passing test. The teardown assumes the reverse which causes the socket to be leaked. 1458471 Resource leak The system resource will not be reclaimed and reused, reducing the future availability of the resource. In test_creds_passing: Leak of memory or pointers to system resources (CWE-404) Reported-by: Coverity Scan Signed-off-by: Jérémie Galarneau Change-Id: I2ead9abbfc189ffbdd71a27f6376d0b001cdc2a3 --- tests/unit/test_unix_socket.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/unit/test_unix_socket.c b/tests/unit/test_unix_socket.c index 0a96fb589..8752ba941 100644 --- a/tests/unit/test_unix_socket.c +++ b/tests/unit/test_unix_socket.c @@ -641,13 +641,6 @@ error: } if (fork_ret == 0) { - if (child_connection_socket >= 0) { - ret = close(child_connection_socket); - if (ret) { - PERROR("Failed to close child connection socket"); - } - } - /* Prevent libtap from printing a result for the child. */ fclose(stdout); fclose(stderr); @@ -655,6 +648,13 @@ error: /* Child exits at the end of this test. */ exit(0); } else if (parent_socket >= 0) { + if (child_connection_socket >= 0) { + ret = close(child_connection_socket); + if (ret) { + PERROR("Failed to close child connection socket"); + } + } + ret = unlink(socket_path); if (ret) { PERROR("Failed to unlink socket at path `%s`", -- 2.34.1