[libcamera-devel] [PATCH 2/4] test: ipc: unixsocket: Close open fds on error paths
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Mon Apr 13 14:31:17 CEST 2020
Hi Umang,
Thank you for the patch.
On Mon, Apr 13, 2020 at 10:46:53AM +0000, Umang Jain wrote:
> Pointed out by Coverity DefectId=279052
>
> Signed-off-by: Umang Jain <email at uajain.com>
> ---
> test/ipc/unixsocket.cpp | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> 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;
> + }
I think we should simplify all this by using the FileDescriptor class.
Looking at IPCUnixSocket::Payload, it seems that fds could be turned
into a vector of FileDescriptor. I haven't however investigated if the
API of the FileDescriptor class would need extensions, or if it's
suitable as-is, but at least here the manual dup() wouldn't be needed,
which already simplifies the code.
Usage of FileDescriptor would also fix a leak of fds in readyRead().
>
> size += calculateLength(clone);
> message->fds.push_back(clone);
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list