[libcamera-devel] [RFC PATCH] ipa: IPADataSerializer: Fix FileDescriptor deserialization

Paul Elder paul.elder at ideasonboard.com
Tue Jul 20 12:28:53 CEST 2021


Previously deserializing a FileDescriptor would use the copy
constructor, causing an fd leak. Fix this by copying the fd integer to
force the FileDescriptor to use the move constructor.

Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>

---
Umang, could you please check if this fixes the issue?

I'll remove the error message; it's just there for debugging (or we can
keep it to protect against unforseen errors?)
---
 src/libcamera/ipa_data_serializer.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/libcamera/ipa_data_serializer.cpp b/src/libcamera/ipa_data_serializer.cpp
index fb941e6b..2a527d5d 100644
--- a/src/libcamera/ipa_data_serializer.cpp
+++ b/src/libcamera/ipa_data_serializer.cpp
@@ -8,6 +8,7 @@
 #include "libcamera/internal/ipa_data_serializer.h"
 
 #include <libcamera/base/log.h>
+#include <unistd.h>
 
 /**
  * \file ipa_data_serializer.h
@@ -547,7 +548,14 @@ FileDescriptor IPADataSerializer<FileDescriptor>::deserialize(std::vector<uint8_
 
 	ASSERT(!(valid && std::distance(fdsBegin, fdsEnd) < 1));
 
-	return valid ? FileDescriptor(*fdsBegin) : FileDescriptor();
+	int tmpfd = valid ? *fdsBegin : -1;
+	FileDescriptor fd = FileDescriptor(tmpfd);
+	if (valid && tmpfd != -1) {
+		LOG(IPADataSerializer, Error) << "We probably leaked an fd";
+		close(tmpfd);
+	}
+
+	return fd;
 }
 
 template<>
-- 
2.27.0



More information about the libcamera-devel mailing list