diff --git a/src/namespace.c b/src/namespace.c index f23da48f8..89a968e36 100644 --- a/src/namespace.c +++ b/src/namespace.c @@ -121,7 +121,8 @@ int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol sock = socket(domain, type, protocol); if (default_namespace >= 0 && ns && setns(default_namespace, CLONE_NEWNET) == -1) { - close(sock); + if (sock >= 0) + close(sock); return -1; } return sock;