sofa icon indicating copy to clipboard operation
sofa copied to clipboard

[objectmodel] Remove memory leaks

Open alxbilger opened this issue 3 years ago • 3 comments
trafficstars

The following code create memory leaks:

static const BaseClass* get()
{
  static TClass<T, Parents> *theClass=new TClass<T, Parents>();
  return theClass;
}

To remove the memory leak, it has to be replaced by:

static const BaseClass* get()
{
  static TClass<T, Parents> theClass;
  return &theClass;
}

However, Parents can be a std::pair, which one of the pair type can be an abstract type. Since it is not possible to instantiate an abstract type, the compilation fails.

This PR removes the use of std::pair to introduce a structure that does not need to instantiate the types. The compilation now succeeds.


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

alxbilger avatar Jul 28 '22 09:07 alxbilger

[ci-build][with-all-tests]

alxbilger avatar Jul 28 '22 11:07 alxbilger

@JeremieA it may be of interest

hugtalbot avatar Aug 10 '22 09:08 hugtalbot

@sofa-framework/reviewers will be merged next week

hugtalbot avatar Aug 17 '22 08:08 hugtalbot