-
Notifications
You must be signed in to change notification settings - Fork 118
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
Changes from 2 commits
fe7e672
f60f0dd
8413f3e
1b8dd88
209cf63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,8 +127,13 @@ create_node( | |
node_impl->secondaryPubListener = tnat_2; | ||
|
||
edp_readers = participant->getEDPReaders(); | ||
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"); | ||
if (edp_readers.first && edp_readers.second) { | ||
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; | ||
} | ||
} else { | ||
RMW_SET_ERROR_MSG("Failed to get valid reader for node subsciber and publisher"); | ||
goto fail; | ||
} | ||
|
||
|
@@ -272,12 +277,12 @@ 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.first->setListener(nullptr)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above of testing the conditions individually. |
||
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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 *>( | ||
|
@@ -237,7 +241,7 @@ rmw_create_service( | |
delete info; | ||
} | ||
|
||
if (rmw_service->service_name != nullptr) { | ||
if (rmw_service && rmw_service->service_name != nullptr) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks to me like a redundant test, because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, if it goes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please apologize, I haven't noticed the modified condition was inside the |
||
rmw_free(const_cast<char *>(rmw_service->service_name)); | ||
rmw_service->service_name = nullptr; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just my personal taste, but I would proof every potentially failing test individually. This makes the error message less ambiguous whether condition 1 or condition 2 fails.
Also, I like the style of testing for negative first and return/goto fail early.
But then again, only my 2 cents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, why I put them together is that:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the current documentation of this function here, one could argue there is no notion that they are always returned NULL - even though this might be the case in the current verison. However, this implementation may change over time, so that we can't certainly rely on this assumption.