Skip to content

Commit

Permalink
Fixed an infinite loop initialization because of a circular reference…
Browse files Browse the repository at this point in the history
… with PropertyManager.
  • Loading branch information
end2endzone committed Aug 19, 2024
1 parent 2ca04e7 commit cf08ca7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/core/PropertyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ namespace shellanything
const std::string PropertyManager::SYSTEM_RANDOM_PATH_PROPERTY_NAME = "random.path";
const std::string PropertyManager::SYSTEM_LOGGING_VERBOSE_PROPERTY_NAME = "system.logging.verbose";

PropertyManager::PropertyManager()
PropertyManager::PropertyManager() :
mInitialized(false)
{
RegisterEnvironmentVariables();
RegisterFixedAndDefaultProperties();
RegisterLiveProperties();
}

PropertyManager::~PropertyManager()
Expand All @@ -71,6 +69,17 @@ namespace shellanything
PropertyManager& PropertyManager::GetInstance()
{
static PropertyManager _instance;
if (!_instance.mInitialized)
{
_instance.mInitialized = true;

// Initialize PropertyManager with default properties.
// Note: The next calls will likely lead to another call to PropertyManager::GetInstance().
// We are using the PropertyManager::mInitialized flag to prevent running into a circular reference
_instance.RegisterEnvironmentVariables();
_instance.RegisterFixedAndDefaultProperties();
_instance.RegisterLiveProperties();
}
return _instance;
}

Expand Down
1 change: 1 addition & 0 deletions src/core/PropertyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ namespace shellanything

void RegisterEnvironmentVariables();
void RegisterFixedAndDefaultProperties();
bool mInitialized; // to prevent calling PropertyManager::GetInstance() while in PropertyManager ctor, creating a circular reference.
PropertyStore properties;
LivePropertyMap live_properties;
};
Expand Down

0 comments on commit cf08ca7

Please sign in to comment.