Bug 1733465 part 4: Convert nsViewManager::gViewManagers to StaticAutoPtr so that we don't have to manually delete it. r=tnikkel

This removes an explicit 'delete', by letting the StaticAutoPtr type handle the
deletion for us automatically and atomically when we clear its value.

Benefits/justification:
* This reduces the potential for double-free bugs.
* This matches existing patterns elsewhere in our code
  (search for e.g. "StaticAutoPtr<nsTArray")
* This reduces (by 1) the number of explicit `delete` calls that we need to
  consider, when auditing the codebase for potential memory safety issues.

Differential Revision: https://phabricator.services.mozilla.com/D127185
This commit is contained in:
Daniel Holbert 2021-10-01 20:38:10 +00:00
Родитель 70f76180d5
Коммит 1d08981c37
2 изменённых файлов: 2 добавлений и 3 удалений

Просмотреть файл

@ -50,7 +50,7 @@ using namespace mozilla::layers;
#undef DEBUG_MOUSE_LOCATION
// Weakly held references to all of the view managers
nsTArray<nsViewManager*>* nsViewManager::gViewManagers = nullptr;
StaticAutoPtr<nsTArray<nsViewManager*>> nsViewManager::gViewManagers;
uint32_t nsViewManager::gLastUserEventTime = 0;
nsViewManager::nsViewManager()
@ -91,7 +91,6 @@ nsViewManager::~nsViewManager() {
if (gViewManagers->IsEmpty()) {
// There aren't any more view managers so
// release the global array of view managers
delete gViewManagers;
gViewManagers = nullptr;
}

Просмотреть файл

@ -424,7 +424,7 @@ class nsViewManager final {
// from here to public should be static and locked... MMP
// list of view managers
static nsTArray<nsViewManager*>* gViewManagers;
static mozilla::StaticAutoPtr<nsTArray<nsViewManager*>> gViewManagers;
};
/**