Tests fix: unix socket: leaked socket of connection to child
[lttng-tools.git] / tests / unit / test_unix_socket.c
index 0a96fb589021cc94d2305e7e744d5e3670e9b021..8752ba94151e9fde22ff34f636ec275d759ddc10 100644 (file)
@@ -641,13 +641,6 @@ error:
        }
 
        if (fork_ret == 0) {
        }
 
        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);
                /* 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) {
                /* 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`",
                ret = unlink(socket_path);
                if (ret) {
                        PERROR("Failed to unlink socket at path `%s`",
This page took 0.024169 seconds and 4 git commands to generate.