-
Notifications
You must be signed in to change notification settings - Fork 91
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
Use correct functions to resize and get an item, avoiding memory leaks in typesupport code #228
Use correct functions to resize and get an item, avoiding memory leaks in typesupport code #228
Conversation
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.
LGTM
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.
I have left some comments here and there.
Thanks for this @iuhilnehc-ynos !!!
rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/TypeSupport_impl.hpp
Outdated
Show resolved
Hide resolved
That's perfect. We (almost) always squash and merge at the end, so the amount of commits in the PR doesn't matter. |
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 so much @iuhilnehc-ynos and @ivanpauno !
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.
LGTM, thanks @iuhilnehc-ynos !!!
@iuhilnehc-ynos some tests are segfaulting, and don't fail with master. |
@@ -78,7 +78,7 @@ struct StringHelper<rosidl_typesupport_introspection_c__MessageMembers> | |||
return std::string(data.data); | |||
} | |||
|
|||
static void assign(cycdeser & deser, void * field, bool) | |||
static void assign(cycdeser & deser, void * field) |
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.
don't you need to do the same in L101?
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.
Yes, we need to remove it. Sorry for my mistake.
I'll retest them(including rcl, rclcpp, system_tests) on my local environment.
If errors still exist, I'll investigate on them.
After debugging rmw_cyclonedds/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/TypeSupport_impl.hpp Lines 525 to 528 in b403b42
and rmw_cyclonedds/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/TypeSupport_impl.hpp Lines 543 to 544 in b403b42
Maybe we can update as following,
from rmw_cyclonedds/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/TypeSupport_impl.hpp Lines 541 to 545 in b403b42
to
add new function
What do you think about it? |
BTW, I have also tested |
Ignore it. The testing master branch is behind of remote. |
This reverts commit 416c01d. Signed-off-by: Chen.Lihui <lihui.chen@sony.com>
Signed-off-by: Chen.Lihui <lihui.chen@sony.com>
Signed-off-by: Chen.Lihui <lihui.chen@sony.com>
Signed-off-by: Chen.Lihui <lihui.chen@sony.com>
Signed-off-by: Chen Lihui <lihui.chen@sony.com> Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Sounds ok to me, but why is that the case? |
Because backtrace log
(gdb) bt
#0 0x00007ffff6ebedad in cycdeser::deserialize (this=0x7fffffff46f0, x=<error reading variable>)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rmw_cyclonedds/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/serdes.hpp:141
#1 0x00007ffff6ebe6a7 in cycdeser::operator>> (this=0x7fffffff46f0, x=<error reading variable>)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rmw_cyclonedds/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/serdes.hpp:101
#2 0x00007ffff6ed3b3c in rmw_cyclonedds_cpp::deserialize_field<bool> (member=0x7ffff6c3bfe0 <BasicTypes__rosidl_typesupport_introspection_c__BasicTypes_message_member_array>,
field=0xff000000, deser=...) at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rmw_cyclonedds/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/TypeSupport_impl.hpp:198
#3 0x00007ffff6eca107 in rmw_cyclonedds_cpp::TypeSupport<rosidl_typesupport_introspection_c__MessageMembers>::deserializeROSmessage (this=0x5555559422c0, deser=...,
members=0x7ffff6c3a5a0 <BasicTypes__rosidl_typesupport_introspection_c__BasicTypes_message_members>, ros_message=0xff000000)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rmw_cyclonedds/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/TypeSupport_impl.hpp:298
#4 0x00007ffff6eca39f in rmw_cyclonedds_cpp::TypeSupport<rosidl_typesupport_introspection_c__MessageMembers>::deserializeROSmessage (this=0x5555559422c0, deser=...,
members=0x7ffff6c3a560 <Arrays__rosidl_typesupport_introspection_c__Arrays_message_members>, ros_message=0x7fffffff64d0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rmw_cyclonedds/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/TypeSupport_impl.hpp:362
#5 0x00007ffff6ec3f69 in rmw_cyclonedds_cpp::TypeSupport<rosidl_typesupport_introspection_c__MessageMembers>::deserializeROSmessage(cycdeser&, void*, std::function<void (cycdeser&)>) (this=0x5555559422c0, deser=..., ros_message=0x7fffffff64d0, prefix=...)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rmw_cyclonedds/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/TypeSupport_impl.hpp:487
#6 0x00007ffff6f191e5 in serdata_rmw_to_sample (dcmn=0x55555594ae90, sample=0x7fffffff64d0, bufptr=0x0, buflim=0x0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rmw_cyclonedds/rmw_cyclonedds_cpp/src/serdata.cpp:284
#7 0x00007ffff6cf2ad9 in ddsi_serdata_to_sample (d=0x55555594ae90, sample=0x7fffffff64d0, bufptr=0x0, buflim=0x0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/eclipse-cyclonedds/cyclonedds/src/security/api/../../core/ddsi/include/dds/ddsi/ddsi_serdata.h:230
#8 0x00007ffff6d739ed in read_take_to_sample (d=0x55555594ae90, sample=0x7fffffff4c30, bufptr=0x0, buflim=0x0)
--Type <RET> for more, q to quit, c to continue without paging--
lonedds/src/core/ddsc/src/dds_rhc_default.c:1956
#9 0x00007ffff6d7415c in take_w_qminv_inst (rhc=0x55555594a870, instptr=0x7fffffff4910, values=0x7fffffff4c30, info_seq=0x7fffffff4c50, max_samples=1, qminv=0, qcmask=0,
ntriggers=0x7fffffff4908, to_sample=0x7ffff6d739b6 <read_take_to_sample>, to_invsample=0x7ffff6d739ef <read_take_to_invsample>)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsc/src/dds_rhc_default.c:2091
#10 0x00007ffff6d74cae in take_w_qminv (rhc=0x55555594a870, lock=true, values=0x7fffffff4c30, info_seq=0x7fffffff4c50, max_samples=1, qminv=0, handle=0, cond=0x0,
to_sample=0x7ffff6d739b6 <read_take_to_sample>, to_invsample=0x7ffff6d739ef <read_take_to_invsample>)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsc/src/dds_rhc_default.c:2227
#11 0x00007ffff6d74ec3 in dds_rhc_take_w_qminv (rhc=0x55555594a870, lock=true, values=0x7fffffff4c30, info_seq=0x7fffffff4c50, max_samples=1, qminv=0, handle=0, cond=0x0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsc/src/dds_rhc_default.c:2251
#12 0x00007ffff6d76a5c in dds_rhc_default_take (rhc_common=0x55555594a870, lock=true, values=0x7fffffff4c30, info_seq=0x7fffffff4c50, max_samples=1, mask=128, handle=0, cond=0x0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsc/src/dds_rhc_default.c:2663
#13 0x00007ffff6d6ec71 in dds_rhc_take (rhc=0x55555594a870, lock=true, values=0x7fffffff4c30, info_seq=0x7fffffff4c50, max_samples=1, mask=128, handle=0, cond=0x0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsc/include/dds/ddsc/dds_rhc.h:83
#14 0x00007ffff6d83767 in dds_read_impl (take=true, reader_or_condition=1794363109, buf=0x7fffffff4c30, bufsz=1, maxs=1, si=0x7fffffff4c50, mask=128, hand=0, lock=true,
only_reader=false) at /home/chenlh/Projects/ROS2/ros2_ws_master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsc/src/dds_read.c:111
#15 0x00007ffff6d83fc4 in dds_take (rd_or_cnd=1794363109, buf=0x7fffffff4c30, si=0x7fffffff4c50, bufsz=1, maxs=1)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsc/src/dds_read.c:332
#16 0x00007ffff6eb3393 in rmw_take_int (subscription=0x555555954eb0, ros_message=0x7fffffff64d0, taken=0x7fffffff4dab, message_info=0x7fffffff4dc0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rmw_cyclonedds/rmw_cyclonedds_cpp/src/rmw_node.cpp:2508
#17 0x00007ffff6eb3db5 in rmw_take_with_info (subscription=0x555555954eb0, ros_message=0x7fffffff64d0, taken=0x7fffffff4dab, message_info=0x7fffffff4dc0, allocation=0x0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rmw_cyclonedds/rmw_cyclonedds_cpp/src/rmw_node.cpp:2675
#18 0x00007ffff7223f24 in rmw_take_with_info (v5=0x555555954eb0, v4=0x7fffffff64d0, v3=0x7fffffff4dab, v2=0x7fffffff4dc0, v1=0x0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rmw_implementation/rmw_implementation/src/functions.cpp:350
#19 0x00007ffff77a0dee in rcl_take (subscription=0x7fffffff6268, ros_message=0x7fffffff64d0, message_info=0x0, allocation=0x0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/rcl/rcl/src/rcl/subscription.c:276
#20 0x00005555555875f4 in TestMessagesFixture::test_message_type<test_msgs__msg__Arrays> (this=0x555555634b80, topic_name=0x5555555dde0a "test_arrays",
ts=0x7ffff7758070 <test_msgs::msg::rosidl_typesupport_c::Arrays_message_type_support_handle>, context=0x555555634ec0)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/system_tests/test_communication/test/test_messages_c.cpp:229
#21 0x000055555556b4f2 in TestMessagesFixture_test_arrays_Test::TestBody (this=0x555555634b80)
at /home/chenlh/Projects/ROS2/ros2_ws_master/src/ros2/system_tests/test_communication/test/test_messages_c.cpp:747
#22 0x00005555555c8e88 in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void> (object=0x555555634b80, method=&virtual testing::Test::TestBody(),
--Type <RET> for more, q to quit, c to continue without paging--
location=0x5555555dfd73 "the test body") at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/./src/gtest.cc:2447
#23 0x00005555555c1885 in testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void> (object=0x555555634b80, method=&virtual testing::Test::TestBody(),
location=0x5555555dfd73 "the test body") at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/./src/gtest.cc:2483
#24 0x000055555559cef4 in testing::Test::Run (this=0x555555634b80) at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/./src/gtest.cc:2522
#25 0x000055555559d8ed in testing::TestInfo::Run (this=0x555555612740)
at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/./src/gtest.cc:2703
#26 0x000055555559dfde in testing::TestCase::Run (this=0x555555611a80)
at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/./src/gtest.cc:2825
#27 0x00005555555a96c7 in testing::internal::UnitTestImpl::RunAllTests (this=0x555555611650)
at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/./src/gtest.cc:5216
#28 0x00005555555ca382 in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x555555611650,
method=(bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const)) 0x5555555a941e <testing::internal::UnitTestImpl::RunAllTests()>,
location=0x5555555e0778 "auxiliary test code (environments or event listeners)")
at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/./src/gtest.cc:2447
#29 0x00005555555c2999 in testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x555555611650,
method=(bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const)) 0x5555555a941e <testing::internal::UnitTestImpl::RunAllTests()>,
location=0x5555555e0778 "auxiliary test code (environments or event listeners)")
at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/./src/gtest.cc:2483
#30 0x00005555555a80a6 in testing::UnitTest::Run (this=0x555555610420 <testing::UnitTest::GetInstance()::instance>)
at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/./src/gtest.cc:4824
#31 0x0000555555594b44 in RUN_ALL_TESTS () at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/include/gtest/gtest.h:2370
#32 0x0000555555594ac6 in main (argc=1, argv=0x7fffffff70f8) at /home/chenlh/Projects/ROS2/ros2_ws_master/local_install_test/gtest_vendor/src/gtest_vendor/src/gtest_main.cc:36
|
7c08f00
to
4d55d82
Compare
I have tested on my local environment.
|
That backtrace shows where it is failing, but it doesn't explain why it is failing. I'm reading the generated "get_function" for C typesupport: void * Arrays__rosidl_typesupport_introspection_c__get_function__BasicTypes__basic_types_values(
void * untyped_member, size_t index)
{
test_msgs__msg__BasicTypes ** member =
(test_msgs__msg__BasicTypes **)(untyped_member);
return &(*member)[index];
} and it looks ok to me, so I'm not quite sure of what caused the segfaults. |
actually, isn't that expecting |
Yes, I think we need to go deep into c typesupport, and find out why the get_function is not working. Maybe I lost something important. |
I also debug it, and I think you're right. After deserializing the members of
but I think maybe it could be updated as following, so it could keep the same logic (to use get_function with field, not &field) with c++ typesupport.
If so, we need to update the template of BTW: I have already updated the |
Yeah, I think that fix is correct, but it would be great to first merge a fix here (I don't think that change in This is unfortunately only happening with C typesupports arrays (not with bounded sequences/sequences), so you'll need special logic to handle that here (it's a bit annoying to add that extra logic, but possible). |
OK, I'll fix it in this way. |
Signed-off-by: Chen.Lihui <lihui.chen@sony.com> Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
4d55d82
to
16e7b1d
Compare
I force-pushed my branch because I removed the |
Failures are unrelated, see: |
Merging! Thanks @iuhilnehc-ynos for this great fix and your patience in the reviewing process!!!! |
Looks like this PR is changing API in publicly accessible headers. On these grounds I don't think we should backport it so I'm removing it from the Foxy release board. |
@jacobperron you mean the "TypeSupport.hpp" and "TypeSupport_impl.hpp"? They are meant to be private to the RMW implementation, they only reside in the public include directory because of a historical accident: they happened to be in that directory when I started the RMW layer without knowing anything about ROS 2 and its directory structure. Note that I am fine with the decision not to merge this fix into Foxy on the off-chance that someone uses those header files — such are the rules of the game. However, the likelihood of anyone actually using them in such a way appears to me to be vanishingly small, and in my view the benefits from fixing the leaks therefore outweigh the downside. But, again, that's just my view. |
@eboasson On second glance, the only "problematic" file is "TypeSupport_impl.hpp". I agree that the likelihood of anyone using it is slim. I could be convinced of backporting this change along with a release note if others want to move forward with the backport. |
…s in typesupport code (ros2#228) Signed-off-by: Chen.Lihui <lihui.chen@sony.com>
…s in typesupport code (ros2#228) Signed-off-by: Chen.Lihui <lihui.chen@sony.com>
This PR is related to #219
NOTE: I used multiple commits in a PR because it'll easy for me to revert some of them if they're unnecessary.
Signed-off-by: Chen.Lihui lihui.chen@sony.com