Fix #92: CallData race condition in Proxy::callMethod

This commit is contained in:
sangelovic
2020-04-02 20:46:38 +02:00
parent dc66efbbcb
commit e91bedd4cb

View File

@ -200,13 +200,15 @@ int Proxy::sdbus_async_reply_handler(sd_bus_message *sdbusMessage, void *userDat
assert(asyncCallData != nullptr); assert(asyncCallData != nullptr);
assert(asyncCallData->callback); assert(asyncCallData->callback);
auto& proxy = asyncCallData->proxy; auto& proxy = asyncCallData->proxy;
auto slot = asyncCallData->slot.get();
SCOPE_EXIT SCOPE_EXIT
{ {
// Slot may be null if we're doing blocking synchronous call implemented by means of asynchronous call, // Slot will be nullptr in case of synchronous call. In that case, the call data lives on the call stack,
// because in that case the call data is still alive on the stack, we don't need to manage it separately. // in another thread. But that thread may have already been woken up by now and cleared its call stack,
if (asyncCallData->slot) // so we can't access asyncCallData here. Hence we save the slot pointer at the beginning of this function.
proxy.pendingAsyncCalls_.removeCall(asyncCallData->slot.get()); if (slot)
proxy.pendingAsyncCalls_.removeCall(slot);
}; };
auto message = Message::Factory::create<MethodReply>(sdbusMessage, &proxy.connection_->getSdBusInterface()); auto message = Message::Factory::create<MethodReply>(sdbusMessage, &proxy.connection_->getSdBusInterface());