From: Alex Rousskov Date: Sun, 14 Dec 2014 11:02:41 +0000 (-0800) Subject: Bug 4057: Avoid on-exit crashes when adaptation is enabled. X-Git-Tag: SQUID_3_4_11~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1ee0ac01a75c5a9a215dc35d429e9486d7e4ade;p=thirdparty%2Fsquid.git Bug 4057: Avoid on-exit crashes when adaptation is enabled. After trunk r13269 (Vector refactor) destroyed vector objects still have positive item counts. This exposes use-after-delete bugs. In this particular case, global adaptation rule/group/service arrays are destructed by global destruction sequence first and then again by Adaptation::*::TheConfig objects destructors. This change avoiding static destruction order dependencies by storing those global adaptation arrays on heap. --- diff --git a/src/adaptation/AccessRule.cc b/src/adaptation/AccessRule.cc index 555a1d82bb..af4b237436 100644 --- a/src/adaptation/AccessRule.cc +++ b/src/adaptation/AccessRule.cc @@ -52,8 +52,8 @@ Adaptation::AccessRule::group() Adaptation::AccessRules & Adaptation::AllRules() { - static AccessRules TheRules; - return TheRules; + static AccessRules *TheRules = new AccessRules; + return *TheRules; } // TODO: make AccessRules::find work diff --git a/src/adaptation/Service.cc b/src/adaptation/Service.cc index 730035db8d..f76c40f8cf 100644 --- a/src/adaptation/Service.cc +++ b/src/adaptation/Service.cc @@ -54,8 +54,8 @@ Adaptation::Service::wants(const ServiceFilter &filter) const Adaptation::Services & Adaptation::AllServices() { - static Services TheServices; - return TheServices; + static Services *TheServices = new Services; + return *TheServices; } Adaptation::ServicePointer diff --git a/src/adaptation/ServiceGroups.cc b/src/adaptation/ServiceGroups.cc index 4fee139d74..c9aaa43eae 100644 --- a/src/adaptation/ServiceGroups.cc +++ b/src/adaptation/ServiceGroups.cc @@ -315,8 +315,8 @@ Adaptation::ServicePlan::print(std::ostream &os) const Adaptation::Groups & Adaptation::AllGroups() { - static Groups TheGroups; - return TheGroups; + static Groups *TheGroups = new Groups; + return *TheGroups; } Adaptation::ServiceGroupPointer