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

Copter: free allocations in case of allocation failure #29167

Merged
merged 1 commit into from
Jan 30, 2025

Conversation

peterbarker
Copy link
Contributor

these would be leaked if the "new" call for the ModeGuidedCustom object failed.

Since resgister_custom_mode may be called multiple times we could leak memory continuously

../../ArduCopter/Copter.cpp:450:41: warning: Potential leak of memory pointed to by 'full_name_copy' [unix.Malloc]
                mode_guided_custom[i] = NEW_NOTHROW ModeGuidedCustom(number, full_name_copy, short_name_copy);
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../libraries/AP_Common/AP_Common.h:192:21: note: expanded from macro 'NEW_NOTHROW'
#define NEW_NOTHROW new(std::nothrow)
                    ^
../../ArduCopter/Copter.cpp:452:17: warning: Potential leak of memory pointed to by 'short_name_copy' [unix.Malloc]
            if (mode_guided_custom[i] == nullptr) {
                ^~~~~~~~~~~~~~~~~~
2 warnings generated.

@rmackay9 rmackay9 requested a review from IamPete1 January 29, 2025 02:09
these would be leaked if the "new" call for the ModeGuidedCustom object failed.

Since resgister_custom_mode may be called multiple times we could leak memory continuously
@peterbarker peterbarker force-pushed the pr/free-strings-custommode branch from e0a23c3 to 265f51c Compare January 29, 2025 02:13
Copy link
Member

@IamPete1 IamPete1 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.

@rmackay9 rmackay9 merged commit c3f2b40 into ArduPilot:master Jan 30, 2025
79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants