Segfault on cancel reservation
Habbus opened this issue · 2 comments
Hi!
First of all, what a cool project! We have been testing this for quite a while, and it is well put together.
When trying to cancel a reservation, the application crashes with a segfault.
This has to do with the following logic in the handleMessage for a CancelReservation.req:
for (const Connector* connector : m_connectors.getConnectors())
{
if ((connector->status == ChargePointStatus::Reserved) && (connector->reservation_id == request.reservationId))
{
// Cancel reservation
m_worker_pool.run<void>([this, &connector] { endReservation(connector->id, true); });
// Prepare response
response.status = CancelReservationStatus::Accepted;
break;
}
}
That lambda that is passed to the worker pool takes a reference to connector, however, this connector pointer only exists here in the scope of the for loop. Updating the worker pool to provide the connector pointer by value fixes the problem for me:
m_worker_pool.run<void>([this, connector] { endReservation(connector->id, true); });
Some extra info:
For me the segfault does not occur when the worker pool runs the function, but in our own logic after the call to reservationEnded in the eventhandler interface. The connectorid that is passed does not make sense anymore.
Hi,
Thanks for the feedback.
I'll prepare a fix which will be available soon on the develop branch.
I'll keep you posted.
Regards.