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

Segmentation error to dereference nullptr #180

Merged
merged 5 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions rmw_fastrtps_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ create_node(
node_impl->secondaryPubListener = tnat_2;

edp_readers = participant->getEDPReaders();
if (!edp_readers.first) {
RMW_SET_ERROR_MSG("edp_readers.first is null");
goto fail;
}

if (!edp_readers.second) {
RMW_SET_ERROR_MSG("edp_readers.second is null");
goto fail;
}

if (!(edp_readers.first->setListener(tnat_1) & edp_readers.second->setListener(tnat_2))) {
RMW_SET_ERROR_MSG("Failed to attach ROS related logic to the Participant");
goto fail;
Expand Down Expand Up @@ -272,12 +282,17 @@ rmw_destroy_node(rmw_node_t * node)

// Begin deleting things in the same order they were created in rmw_create_node().
std::pair<StatefulReader *, StatefulReader *> edp_readers = participant->getEDPReaders();
if (!edp_readers.first->setListener(nullptr)) {
if (!edp_readers.first || !edp_readers.second) {
RMW_SET_ERROR_MSG("failed to get EDPReader listener");
result_ret = RMW_RET_ERROR;
}

if (edp_readers.first && !edp_readers.first->setListener(nullptr)) {
RMW_SET_ERROR_MSG("failed to unset EDPReader listener");
result_ret = RMW_RET_ERROR;
}
delete impl->secondarySubListener;
if (!edp_readers.second->setListener(nullptr)) {
if (edp_readers.second && !edp_readers.second->setListener(nullptr)) {
RMW_SET_ERROR_MSG("failed to unset EDPReader listener");
result_ret = RMW_RET_ERROR;
}
Expand Down
6 changes: 5 additions & 1 deletion rmw_fastrtps_cpp/src/rmw_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ rmw_create_service(
}

rmw_service = rmw_service_allocate();
if (!rmw_service) {
RMW_SET_ERROR_MSG("failed to allocate memory for service");
goto fail;
}
rmw_service->implementation_identifier = eprosima_fastrtps_identifier;
rmw_service->data = info;
rmw_service->service_name = reinterpret_cast<const char *>(
Expand Down Expand Up @@ -237,7 +241,7 @@ rmw_create_service(
delete info;
}

if (rmw_service->service_name != nullptr) {
if (rmw_service && rmw_service->service_name) {
rmw_free(const_cast<char *>(rmw_service->service_name));
rmw_service->service_name = nullptr;
}
Expand Down