Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions plugins/cache_promote/configs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ static const struct option longopt[] = {
// The destructor is responsible for returning the policy to the PolicyManager.
PromotionConfig::~PromotionConfig()
{
_manager->releasePolicy(_policy);
if (_policy != nullptr) {
_manager->releasePolicy(_policy);
}
}

// Parse the command line arguments to the plugin, and instantiate the appropriate policy
Expand Down Expand Up @@ -86,10 +88,8 @@ PromotionConfig::factory(int argc, char *argv[])
TSDebug(PLUGIN_NAME, "internal_enabled set to true");
} else {
if (!_policy->parseOption(opt, optarg)) {
TSError("[%s] The specified policy (%s) does not support the -%c option", PLUGIN_NAME, _policy->policyName(), opt);
delete _policy;
_policy = nullptr;
return false;
TSError("[%s] The specified policy (%s) does not support the -%c option; skipping this argument", PLUGIN_NAME,
_policy->policyName(), opt);
}
}
} else {
Expand All @@ -99,6 +99,10 @@ PromotionConfig::factory(int argc, char *argv[])
}
}

if (_policy == nullptr) {
return false;
}

// Coalesce any LRU policies via the LRU manager. This is a little ugly, but it makes configuration
// easier, and order of options doesn't matter.

Expand Down
12 changes: 7 additions & 5 deletions plugins/cache_promote/policy_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PolicyManager::releasePolicy(PromotionPolicy *policy)
{
std::string tag = policy->id();

if (tag.size() != 0) {
if (tag.size() != 0) { // this is always the case for instances of LRUPolicy
auto res = _policies.find(tag);

if (res != _policies.end()) {
Expand All @@ -57,11 +57,13 @@ PolicyManager::releasePolicy(PromotionPolicy *policy)
delete res->second.first;
_policies.erase(res);
}

return;
} else {
TSAssert(!"Trying to release a policy which was not acquired via PolicyManager");
TSDebug(PLUGIN_NAME, "Tried to release a policy which was not properly initialized nor acquired via PolicyManager");
}
} else {
// Not managed by the policy manager, so just nuke it.
delete policy;
}

// Not managed by the policy manager, so just nuke it.
delete policy;
}