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

Initialize sample buffer pointer with nullptr #27024

Closed
wants to merge 1 commit into from
Closed

Initialize sample buffer pointer with nullptr #27024

wants to merge 1 commit into from

Conversation

reznikmm
Copy link

@reznikmm reznikmm commented May 9, 2024

to avoid memory corruption on deallocating uninitialized value in CompassCalibrator.cpp:384:

if (_sample_buffer != nullptr) {
    free(_sample_buffer);

to avoid memory corruption on deallocating uninitialized value in `CompassCalibrator.cpp`:384:

```c
if (_sample_buffer != nullptr) {
    free(_sample_buffer);
```
@@ -79,7 +79,8 @@ extern const AP_HAL::HAL& hal;
///////////////////// PUBLIC INTERFACE /////////////////////
////////////////////////////////////////////////////////////

CompassCalibrator::CompassCalibrator()
CompassCalibrator::CompassCalibrator() :
_sample_buffer(nullptr)
Copy link
Contributor

Choose a reason for hiding this comment

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

For this to be a problem we'd have to have allocated this on the stack, essentially: https://ardupilot.org/dev/docs/style-guide.html#implicit-zeroing-of-memory

Do you still see a problem here?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, in my case it was on the stack. Thank you for the reference. Feel free to close PR then and sorry for the noise.

@peterbarker
Copy link
Contributor

Thanks anyway, @reznikmm

@peterbarker peterbarker closed this May 9, 2024
@reznikmm reznikmm deleted the patch-1 branch May 10, 2024 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants