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 memory leak and undefined behavour in Updater.cpp (UpdaterClass) #8671

Merged
merged 4 commits into from
Oct 6, 2023

Conversation

MathewHDYT
Copy link
Contributor

@MathewHDYT MathewHDYT commented Sep 25, 2023

Description of Change

The pull request aims to fix undefined behaviour and a memory leak of 16 bytes every time the UpdaterClass is used, this occurs because the _skipBuffer is not freed correctly and the _buffer is deleted but using the C++ style delete[], even tough the C style memory allocation malloc was used. Which is not compatible and is undefined behavour. Meaning it might work on some devices on others it might crash and on some it might do other things.

The changes are compatible with the current API and do not change anything about the UpdaterClass public or private method. It doesn't even change the private members. It only adjusts the memory allocation to always use C++ style new and to actually free the created memory with delete[].


A more detailed description can be found in the issue mentioned below as well.

Tests scenarios

The changed code has been tested with an ESP32 and updating the device with the UpdaterClass over OTA.

Related links

Closes #7984

@CLAassistant
Copy link

CLAassistant commented Sep 25, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@mrengineer7777 mrengineer7777 left a comment

Choose a reason for hiding this comment

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

Codefix looks good to me. Is this targeting the correct branch?

@MathewHDYT
Copy link
Contributor Author

Codefix looks good to me. Is this targeting the correct branch?

@mrengineer7777 Not sure perhaps targeting release/v2.x makes more sense. If I need to pull to another branch instead I can simply change the branch of this pull request if so required.

@me-no-dev
Copy link
Member

perhaps targeting release/v2.x makes more sense

no. leave it as is. We will not update 2.x anymore and will merge 5.1 into master to focus on 3.0.0

@VojtechBartoska VojtechBartoska added this to the 3.0.0 milestone Sep 26, 2023
@VojtechBartoska VojtechBartoska added the Area: Performance Issue related to performance problems and improvements label Sep 27, 2023
Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

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

@MathewHDYT When updating this part of code, can you change the error messages as suggested? :) Thanks, otherwise LGTM.

libraries/Update/src/Updater.cpp Outdated Show resolved Hide resolved
libraries/Update/src/Updater.cpp Outdated Show resolved Hide resolved
MathewHDYT and others added 2 commits October 4, 2023 12:38
Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@users.noreply.github.com>
Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@users.noreply.github.com>
@P-R-O-C-H-Y P-R-O-C-H-Y added the Status: Pending Merge Pull Request is ready to be merged label Oct 4, 2023
@me-no-dev me-no-dev merged commit 709c935 into espressif:master Oct 6, 2023
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Performance Issue related to performance problems and improvements Status: Pending Merge Pull Request is ready to be merged
Projects
Development

Successfully merging this pull request may close these issues.

Arduino OTA Updater has memory leak in certain conditions
6 participants