diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp
index 5348f35..4fc6606 100644
--- a/test/ipc/unixsocket.cpp
+++ b/test/ipc/unixsocket.cpp
@@ -470,8 +470,10 @@ private:
 		int size = 0;
 		for (unsigned int i = 0; i < num; i++) {
 			int clone = dup(fd);
-			if (clone < 0)
+			if (clone < 0) {
+				close(fd);
 				return clone;
+			}
 
 			size += calculateLength(clone);
 			message->fds.push_back(clone);
