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 compiler warning and potential heap corruption due to mismatched new/delete #1211

Merged
merged 1 commit into from
Mar 26, 2018

Conversation

meyerj
Copy link
Contributor

@meyerj meyerj commented Mar 26, 2018

This fixes a -Wmismatched-new-delete compiler warning with Apple LLVM version 9.0.0 (clang-900.0.39.2) in macOS Sierra:

[ 77%] Building CXX object src/rviz/default_plugin/CMakeFiles/rviz_default_plugin.dir/map_display.cpp.o
/Users/vagrant/ros_kinetic_desktop_ws/src/rviz/src/rviz/default_plugin/map_display.cpp:213:3: warning: 'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'? [-Wmismatched-new-delete]
  delete pixels;
  ^
        []
/Users/vagrant/ros_kinetic_desktop_ws/src/rviz/src/rviz/default_plugin/map_display.cpp:183:27: note: allocated with 'new[]' here
  unsigned char* pixels = new unsigned char[pixels_size];
                          ^

According to the C++ FAQ and the critical C++ FQA this is undefined behavior and can potentially lead to heap corruption. Probably it would be a good idea to use boost::shared_array instead for exception safety.

Note that I did not look into the source code in detail or check whether and when the Swatch::updateData() function is called.

@wjwwood wjwwood added the bug label Mar 26, 2018
Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks! I'll just wait for CI to catch up before merging.

@wjwwood wjwwood merged commit 82fe57a into ros-visualization:kinetic-devel Mar 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants