Skip to content

Commit

Permalink
Copter: free allocations in case of allocation failure
Browse files Browse the repository at this point in the history
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
  • Loading branch information
peterbarker authored and rmackay9 committed Jan 30, 2025
1 parent 2ef98e1 commit c3f2b40
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ArduCopter/Copter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ AP_Vehicle::custom_mode_state* Copter::register_custom_mode(const uint8_t num, c
}
if (mode_guided_custom[i] == nullptr) {
// Allocation failure
free((void*)full_name_copy);
free((void*)short_name_copy);
return nullptr;
}

Expand Down

0 comments on commit c3f2b40

Please sign in to comment.