[{"id":4433,"web_url":"https://patchwork.libcamera.org/comment/4433/","msgid":"<20200413123117.GA4875@pendragon.ideasonboard.com>","date":"2020-04-13T12:31:17","subject":"Re: [libcamera-devel] [PATCH 2/4] test: ipc: unixsocket: Close open\n\tfds on error paths","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Mon, Apr 13, 2020 at 10:46:53AM +0000, Umang Jain wrote:\n> Pointed out by Coverity DefectId=279052\n> \n> Signed-off-by: Umang Jain <email@uajain.com>\n> ---\n>  test/ipc/unixsocket.cpp | 4 +++-\n>  1 file changed, 3 insertions(+), 1 deletion(-)\n> \n> diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp\n> index 5348f35..4fc6606 100644\n> --- a/test/ipc/unixsocket.cpp\n> +++ b/test/ipc/unixsocket.cpp\n> @@ -470,8 +470,10 @@ private:\n>  \t\tint size = 0;\n>  \t\tfor (unsigned int i = 0; i < num; i++) {\n>  \t\t\tint clone = dup(fd);\n> -\t\t\tif (clone < 0)\n> +\t\t\tif (clone < 0) {\n> +\t\t\t\tclose(fd);\n>  \t\t\t\treturn clone;\n> +\t\t\t}\n\nI think we should simplify all this by using the FileDescriptor class.\nLooking at IPCUnixSocket::Payload, it seems that fds could be turned\ninto a vector of FileDescriptor. I haven't however investigated if the\nAPI of the FileDescriptor class would need extensions, or if it's\nsuitable as-is, but at least here the manual dup() wouldn't be needed,\nwhich already simplifies the code.\n\nUsage of FileDescriptor would also fix a leak of fds in readyRead().\n\n>  \n>  \t\t\tsize += calculateLength(clone);\n>  \t\t\tmessage->fds.push_back(clone);","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E70F6279B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Apr 2020 14:31:29 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0F5D124B;\n\tMon, 13 Apr 2020 14:31:29 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"wQ16rIVF\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1586781089;\n\tbh=62AHSYDSHRnOBAj66Xu0ylvI/hCpeHtmYXjgdRicTko=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=wQ16rIVF641fhY0i6oai7f4dDrN3A0dKCYYNig8GNAV98/5inE8gr+fiwe5yxuxhg\n\tzHXjqafyWCIr0IAAmyqGCpBtYZG6OtPatyXSHep11Jv8PT6aQKFmfjt5eOu7hNV7dY\n\trcIhA+o5ZslK9lAILNr675sIpwDNUz9VTjkGr1TA=","Date":"Mon, 13 Apr 2020 15:31:17 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Umang Jain <email@uajain.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200413123117.GA4875@pendragon.ideasonboard.com>","References":"<20200413104631.12276-1-email@uajain.com>\n\t<20200413104631.12276-3-email@uajain.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200413104631.12276-3-email@uajain.com>","Subject":"Re: [libcamera-devel] [PATCH 2/4] test: ipc: unixsocket: Close open\n\tfds on error paths","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 13 Apr 2020 12:31:29 -0000"}}]