Skip to content

Handle properly the exceptions returned by FGCondition#1244

Merged
bcoconni merged 2 commits intoJSBSim-Team:masterfrom
bcoconni:FGCondition_exception
Mar 12, 2025
Merged

Handle properly the exceptions returned by FGCondition#1244
bcoconni merged 2 commits intoJSBSim-Team:masterfrom
bcoconni:FGCondition_exception

Conversation

@bcoconni
Copy link
Member

@bcoconni bcoconni commented Mar 10, 2025

The constructor of FGCondition may throw exceptions of type JSBSim::BaseException when a <condition> element is improperly specified in the XML input files. The constructor of FGCondition is called by FGScript::LoadScript and the constructor of FGDistributor but none of them are handling properly the case where an exception is thrown by FGCondition:

  • The method FGScript::LoadScript expects an exception of type std::string and therefore misses the deletion of the variable newEvent when FGCondition throws an exception BaseException.
  • The constructor of FGDistributor does not catch any exception thrown by FGCondition so the variable current_case is not deleted when FGCondition throws.

These are 2 potential memory leaks that occur when JSBSim finds an error in a <condition> element.

Fixing these memory leaks have brought an opportunity to avoid the constructor of FGCondition outputting messages in the console. The error messages are now issued by the callers of the constructor of FGCondition which saves passing the instance of FGLogger to the constructor of FGCondition.

@codecov
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

Attention: Patch coverage is 36.84211% with 12 lines in your changes missing coverage. Please review.

Project coverage is 24.77%. Comparing base (91ebed4) to head (356ec43).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/models/flight_control/FGDistributor.cpp 0.00% 8 Missing ⚠️
src/input_output/FGScript.cpp 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1244      +/-   ##
==========================================
- Coverage   24.80%   24.77%   -0.04%     
==========================================
  Files         169      169              
  Lines       19425    19425              
==========================================
- Hits         4819     4812       -7     
- Misses      14606    14613       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bcoconni bcoconni merged commit bd3b8f6 into JSBSim-Team:master Mar 12, 2025
29 checks passed
@bcoconni bcoconni deleted the FGCondition_exception branch March 12, 2025 18:48
bcoconni added a commit to bcoconni/jsbsim that referenced this pull request Mar 21, 2025
bcoconni added a commit to bcoconni/jsbsim that referenced this pull request Mar 21, 2025
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.

1 participant