Message ID | 20200413104631.12276-3-email@uajain.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
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@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);
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);
Pointed out by Coverity DefectId=279052 Signed-off-by: Umang Jain <email@uajain.com> --- test/ipc/unixsocket.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)