Skip to content

Fix memory leak and handle realloc failure#24291

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
visitorckw:fix-memory-leak
Sep 20, 2023
Merged

Fix memory leak and handle realloc failure#24291
asmorkalov merged 1 commit intoopencv:4.xfrom
visitorckw:fix-memory-leak

Conversation

@visitorckw
Copy link
Copy Markdown
Contributor

@visitorckw visitorckw commented Sep 18, 2023

In the previous code, there was a memory leak issue where the previously allocated memory was not freed upon a failed realloc operation. This commit addresses the problem by releasing the old memory before setting the pointer to NULL in case of a realloc failure. This ensures that memory is properly managed and avoids potential memory leaks.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.

In the previous code, there was a memory leak issue where the
previously allocated memory was not freed upon a failed realloc
operation. This commit addresses the problem by releasing the old
memory before setting the pointer to NULL in case of a realloc failure.
This ensures that memory is properly managed and avoids potential
memory leaks.
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

👍

@asmorkalov asmorkalov merged commit 799bb0c into opencv:4.x Sep 20, 2023
@asmorkalov asmorkalov mentioned this pull request Sep 28, 2023
@visitorckw visitorckw deleted the fix-memory-leak branch December 29, 2023 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants