Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segmentation fault in test cases #777

Merged
merged 1 commit into from
Sep 9, 2024
Merged

Conversation

Pietfried
Copy link
Contributor

@Pietfried Pietfried commented Sep 8, 2024

Describe your changes

With the introduction of the connectivity_manager in #748 the connectivity_manager was defined before the device_model in the ChargePoint class.

class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBase {
private:
    std::unique_ptr<ConnectivityManager> connectivity_manager;
    std::shared_ptr<DeviceModel> device_model;
    ...
}

This caused the destructor of the device_model to be executed before the destructor of the connectivity_manager.

DeviceModel::~
ConnectivityManager::~

This can lead to a segmentation fault in test cases where the ChargePointFixture was used. The websocket_disconnected_callback makes use of the device_model which can aleady be null at this time: https://github.com/EVerest/libocpp/blob/main/lib/ocpp/v201/charge_point.cpp#L3834

This PR changes the order of the definition of device_model and connectivity_manager so that the destructor of the ConnectivityManager is executed before the one of the DeviceModel.

Issue ticket number and link

#770

Checklist before requesting a review

@Pietfried Pietfried linked an issue Sep 9, 2024 that may be closed by this pull request
@Pietfried Pietfried changed the title Returning immediately in websocket_disconnected_callback in case devi… Fix segmentation fault in test cases Sep 9, 2024
…ager execute befroe the one of the device_model

Signed-off-by: pietfried <pietgoempel@gmail.com>
@maaikez
Copy link
Contributor

maaikez commented Sep 9, 2024

Shouldn't we also add a check in the websocket_disconnected_callback then maybe?

Other than that: well, it can be so small.... nice find!

@Pietfried
Copy link
Contributor Author

Shouldn't we also add a check in the websocket_disconnected_callback then maybe?

Other than that: well, it can be so small.... nice find!

device_model should not happen to be null anymore, since the websocket destructor makes sure the (all) the callback(s) are executed before the object is destroyed

@Pietfried Pietfried merged commit 70b67a9 into main Sep 9, 2024
4 checks passed
@Pietfried Pietfried deleted the bugfix/test-case-segfault branch September 9, 2024 13:31
SNSubramanya pushed a commit that referenced this pull request Sep 11, 2024
…ager execute befroe the one of the device_model (#777)

Signed-off-by: pietfried <pietgoempel@gmail.com>
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libocpp segfaults on Alpine Linux
3 participants