Skip to content

Memory leak fix and general improvements of FGDistributor#1245

Merged
agodemar merged 2 commits intoJSBSim-Team:masterfrom
bcoconni:FGDistributor_memory_leak
Mar 17, 2025
Merged

Memory leak fix and general improvements of FGDistributor#1245
agodemar merged 2 commits intoJSBSim-Team:masterfrom
bcoconni:FGDistributor_memory_leak

Conversation

@bcoconni
Copy link
Member

This is a follow up of PR #1244: the destructor FGDistributor::Case::~Case is not deleting its member Test because the call to delete Test is missing. It should have been:

    ~Case() {
      for (auto pair: PropValPairs) delete pair;
+     delete Test;
    }

Given this and the leak that has been fixed in PR #1244, this PR is addressing the issue upfront and replaces all pointers in FGDistributor by smart pointers (namely std::unique_ptr<>) which should fix all sources of memory leakage in FGDistributor.

The opportunity is taken to rename the iterator methods of the class FGDistributor::Case from IterPropValPairs, EndPropValPairs to the standardized names begin, end. This allows using a for-range loop instead of an explicit for loop:

-        for (auto propVal = Case->IterPropValPairs(); propVal != Case->EndPropValPairs(); ++propVal) {
+        for (const auto& propVal: *Case) {

which is easier to read.

Finally, the methods FGCondition::Evaluate and FGCondition::PrintCondition are constified to ensure that they are not having side effects on the instances of the class FGDistributor::Case.

Please note that the class FGDistributor::Case is private to FGDistributor and modifying its API has no side effects beyond the internal code of FGDistributor.

bcoconni and others added 2 commits March 13, 2025 00:14
@codecov
Copy link

codecov bot commented Mar 14, 2025

Codecov Report

Attention: Patch coverage is 3.33333% with 29 lines in your changes missing coverage. Please review.

Project coverage is 24.77%. Comparing base (bd3b8f6) to head (4ed42c9).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/models/flight_control/FGDistributor.h 0.00% 16 Missing ⚠️
src/models/flight_control/FGDistributor.cpp 0.00% 12 Missing ⚠️
src/math/FGCondition.cpp 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1245   +/-   ##
=======================================
  Coverage   24.77%   24.77%           
=======================================
  Files         169      169           
  Lines       19425    19421    -4     
=======================================
  Hits         4812     4812           
+ Misses      14613    14609    -4     

☔ 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 added the bug label Mar 14, 2025
@agodemar agodemar merged commit 40fe739 into JSBSim-Team:master Mar 17, 2025
50 of 51 checks passed
@bcoconni bcoconni deleted the FGDistributor_memory_leak branch March 17, 2025 23:18
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants