ros2 / rclc

ROS Client Library for the C language.
Apache License 2.0
118 stars 42 forks source link

fix rclc_example: memory leaking in msg.data allocation #386

Closed Zard-C closed 1 year ago

Zard-C commented 1 year ago

Fix bug: memory leaking while msg.data allocation.

This bug is caused by using malloc allocate memory for the std_msg.data.data, but we call std_msgsmsgString__init(), msg.data.data was allocated a block memory which size is 1, thus we should use allocator.reallocate to reallocate memory for msg.data.data.

Fixes #385

Signed-off-by: Zard-C patrick.zhang5233@gmail.com

codecov-commenter commented 1 year ago

Codecov Report

Merging #386 (3a1d6cb) into humble (27703c2) will decrease coverage by 0.08%. Report is 2 commits behind head on humble. The diff coverage is n/a.

@@            Coverage Diff             @@
##           humble     #386      +/-   ##
==========================================
- Coverage   69.13%   69.06%   -0.08%     
==========================================
  Files          16       16              
  Lines        2715     2715              
  Branches      765      765              
==========================================
- Hits         1877     1875       -2     
- Misses        451      452       +1     
- Partials      387      388       +1     

see 1 file with indirect coverage changes

JanStaschulat commented 1 year ago

@Zard-C thank you for this pull request!

JanStaschulat commented 1 year ago

@mergifyio backport rolling

mergify[bot] commented 1 year ago

backport rolling

✅ Backports have been created

* [#387 fix rclc_example: memory leaking in msg.data allocation (backport #386)](https://github.com/ros2/rclc/pull/387) has been created for branch `rolling`