[libcamera-devel] [PATCH v2 1/2] test: ipc: unixsocket: Close open fds on error paths
Umang Jain
email at uajain.com
Wed Apr 15 17:04:14 CEST 2020
Pointed out by Coverity DefectId=279052
Signed-off-by: Umang Jain <email at uajain.com>
---
test/ipc/unixsocket.cpp | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp
index 5348f35..7bc6a89 100644
--- a/test/ipc/unixsocket.cpp
+++ b/test/ipc/unixsocket.cpp
@@ -16,6 +16,7 @@
#include <unistd.h>
#include <libcamera/event_dispatcher.h>
+#include <libcamera/file_descriptor.h>
#include <libcamera/timer.h>
#include "ipc_unixsocket.h"
@@ -467,18 +468,22 @@ private:
if (fd < 0)
return fd;
+ FileDescriptor file_desc = FileDescriptor(fd);
+ close(fd);
+ if (file_desc.fd() < 0)
+ return file_desc.fd();
+
int size = 0;
for (unsigned int i = 0; i < num; i++) {
- int clone = dup(fd);
- if (clone < 0)
- return clone;
+ FileDescriptor *clone = new FileDescriptor(file_desc.fd());
+ int clone_int = clone->fd();
+ if (clone_int < 0)
+ return clone_int;
- size += calculateLength(clone);
- message->fds.push_back(clone);
+ size += calculateLength(clone_int);
+ message->fds.push_back(clone_int);
}
- close(fd);
-
return size;
}
--
2.26.0
More information about the libcamera-devel
mailing list