Skip to content

Circular reference in Application::loadConfiguration() #5322

@aleks-f

Description

@aleks-f

Problem

Application::loadConfiguration() creates a circular reference when loading .properties files:

_pConfig->add(new PropertyFileConfiguration(confPath.toString(), 
    AbstractConfiguration::Ptr(_pConfig, true)), priority, false);

_pConfig (LayeredConfiguration) owns the PropertyFileConfiguration, and the PropertyFileConfiguration holds _pParentConfig (an AutoPtr) back to the same LayeredConfiguration. This cycle prevents proper cleanup — detected as indirect memory leaks by AddressSanitizer.

The AbstractConfiguration::Ptr(_pConfig, true) with shared=true skips duplicate() on construction but still calls release() on destruction, causing ref count issues on top of the cycle.

Fix

Change PropertyFileConfiguration's parent config parameter and member from AbstractConfiguration::Ptr (owning smart pointer) to AbstractConfiguration* (non-owning raw pointer). The parent configuration always outlives the child — LayeredConfiguration owns the PropertyFileConfiguration, so the back-pointer is guaranteed valid for the child's lifetime.

Affected code

  • Util/include/Poco/Util/PropertyFileConfiguration.h — constructor parameters and member type changed to raw pointer, with ownership documentation
  • Util/src/PropertyFileConfiguration.cpp — constructors updated to match
  • Util/src/Application.cpp — callers pass _pConfig.get() instead of creating a temporary `AutoPtr

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions