Received: from eggs.gnu.org ([2001:4830:134:3::10]:44001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlX3x-0004nI-V4 for qemu-devel@nongnu.org; Mon, 12 Oct 2015 02:58:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZlX3u-0004Lx-OH for qemu-devel@nongnu.org; Mon, 12 Oct 2015 02:58:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53302) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlX3u-0004Ky-Ii for qemu-devel@nongnu.org; Mon, 12 Oct 2015 02:58:22 -0400 From: Markus Armbruster References: <20151009114853.30686.38761.malonedeb@soybean.canonical.com> Date: Mon, 12 Oct 2015 08:58:17 +0200 In-Reply-To: <20151009114853.30686.38761.malonedeb@soybean.canonical.com> (Mark Pizzolato's message of "Fri, 09 Oct 2015 11:48:53 -0000") Message-ID: <8737xg8tfa.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [Bug 1504513] [NEW] Socket leak on each call to qemu_socket() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mark Pizzolato Cc: Bug 1504513 <1504513@bugs.launchpad.net>, qemu-devel@nongnu.org Mark Pizzolato writes: > Public bug reported: > > On any host platform where SOCK_CLOEXEC is defined (Linux at least), a > socket is leaked on each call to qemu_socket() AND the socket returned > hasn't been created with the desired SOCK_CLOEXEC attribute. The > qemu_socket routine is: > > Line 272 of util/osdep.c: > /* > * Opens a socket with FD_CLOEXEC set > */ > int qemu_socket(int domain, int type, int protocol) > { > int ret; > > #ifdef SOCK_CLOEXEC > ret = socket(domain, type | SOCK_CLOEXEC, protocol); > if (ret != -1 || errno != EINVAL) { > return ret; If socket() succeeded (ret != -1), we return the socket. If socket() failed with anything but EINVAL (ret == -1 && errno != EINVAL), we return -1 with errno set. > } Here, ret == -1 && errno == EINVAL. > #endif > ret = socket(domain, type, protocol); > if (ret >= 0) { > qemu_set_cloexec(ret); > } > > return ret; > } How can this leak a socket? How can this return a socket with FD_CLOEXEC not set?