From bd10ec46051ef35b0ba8f824e983c4bde30150b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Tue, 22 Jul 2025 10:25:51 +0200 Subject: [PATCH] utils: codegen: ipc: Check `ipc_` instead of `isolate_` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only try to send the "Exit" message if the `IPCPipeUnixSocket` object exists. If the constructor fails, then `ipc_` might remain nullptr, which would lead to a nullptr dereference in the destructor. This change also modifies the constructor so that only a valid `IPCPipeUnixSocket` object will be saved into the `ipc_` member, which avoids error messages when `IPCPipeUnixSocket::sendAsync()` is callded in the inappropriate state. Bug: https://bugs.libcamera.org/show_bug.cgi?id=276 Signed-off-by: Barnabás Pőcze Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- .../libcamera_templates/module_ipa_proxy.cpp.tmpl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl index 9a3aadbd..beb646e2 100644 --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl @@ -61,15 +61,16 @@ namespace {{ns}} { return; } - ipc_ = std::make_unique(ipam->path().c_str(), - proxyWorkerPath.c_str()); - if (!ipc_->isConnected()) { + auto ipc = std::make_unique(ipam->path().c_str(), + proxyWorkerPath.c_str()); + if (!ipc->isConnected()) { LOG(IPAProxy, Error) << "Failed to create IPCPipe"; return; } - ipc_->recv.connect(this, &{{proxy_name}}::recvMessage); + ipc->recv.connect(this, &{{proxy_name}}::recvMessage); + ipc_ = std::move(ipc); valid_ = true; return; } @@ -96,7 +97,7 @@ namespace {{ns}} { {{proxy_name}}::~{{proxy_name}}() { - if (isolate_) { + if (ipc_) { IPCMessage::Header header = { static_cast({{cmd_enum_name}}::Exit), seq_++ }; IPCMessage msg(header);