utils: codegen: ipc: Check ipc_ instead of isolate_

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 <barnabas.pocze@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Barnabás Pőcze
2025-07-22 10:25:51 +02:00
parent e0fcbea494
commit bd10ec4605

View File

@@ -61,15 +61,16 @@ namespace {{ns}} {
return;
}
ipc_ = std::make_unique<IPCPipeUnixSocket>(ipam->path().c_str(),
proxyWorkerPath.c_str());
if (!ipc_->isConnected()) {
auto ipc = std::make_unique<IPCPipeUnixSocket>(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<uint32_t>({{cmd_enum_name}}::Exit), seq_++ };
IPCMessage msg(header);