Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 27df9c5

Browse files
committed
Bug 913138 - Shut down imagelib at the end of layout shutdown. r=bsmedberg
1 parent afef348 commit 27df9c5

4 files changed

Lines changed: 46 additions & 8 deletions

File tree

image/build/moz.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# License, v. 2.0. If a copy of the MPL was not distributed with this
55
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
66

7+
EXPORTS += [
8+
'nsImageModule.h',
9+
]
10+
711
SOURCES += [
812
'nsImageModule.cpp',
913
]

image/build/nsImageModule.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66

7+
#include "nsImageModule.h"
8+
79
#include "mozilla/ModuleUtils.h"
810
#include "nsMimeTypes.h"
911

@@ -79,23 +81,29 @@ static const mozilla::Module::CategoryEntry kImageCategories[] = {
7981
{ nullptr }
8082
};
8183

82-
static nsresult
83-
imglib_Initialize()
84+
static bool sInitialized = false;
85+
nsresult
86+
mozilla::image::InitModule()
8487
{
8588
mozilla::image::DiscardTracker::Initialize();
8689
mozilla::image::ImageFactory::Initialize();
8790
mozilla::image::RasterImage::Initialize();
8891
mozilla::image::SurfaceCache::Initialize();
8992
imgLoader::GlobalInit();
93+
sInitialized = true;
9094
return NS_OK;
9195
}
9296

93-
static void
94-
imglib_Shutdown()
97+
void
98+
mozilla::image::ShutdownModule()
9599
{
100+
if (!sInitialized) {
101+
return;
102+
}
96103
imgLoader::Shutdown();
97104
mozilla::image::SurfaceCache::Shutdown();
98105
mozilla::image::DiscardTracker::Shutdown();
106+
sInitialized = false;
99107
}
100108

101109
static const mozilla::Module kImageModule = {
@@ -104,8 +112,11 @@ static const mozilla::Module kImageModule = {
104112
kImageContracts,
105113
kImageCategories,
106114
nullptr,
107-
imglib_Initialize,
108-
imglib_Shutdown
115+
mozilla::image::InitModule,
116+
// We need to be careful about shutdown ordering to avoid intermittent crashes
117+
// when hashtable enumeration decides to destroy modules in an unfortunate
118+
// order. So our shutdown is invoked explicitly during layout module shutdown.
119+
nullptr
109120
};
110121

111122
NSMODULE_DEFN(nsImageLib2Module) = &kImageModule;

image/build/nsImageModule.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#ifndef nsImageModule_h
7+
#define nsImageModule_h
8+
9+
#include "nsError.h"
10+
11+
namespace mozilla {
12+
namespace image {
13+
14+
nsresult InitModule();
15+
void ShutdownModule();
16+
17+
} /* namespace image */
18+
} /* namespace mozilla */
19+
20+
21+
#endif /* nsImageModule_h */

layout/build/nsLayoutModule.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "XPCModule.h"
99
#include "mozilla/ModuleUtils.h"
10+
#include "nsImageModule.h"
1011
#include "nsLayoutStatics.h"
1112
#include "nsContentCID.h"
1213
#include "nsContentDLF.h"
@@ -1252,8 +1253,9 @@ LayoutModuleDtor()
12521253
nsScriptSecurityManager::Shutdown();
12531254
xpcModuleDtor();
12541255

1255-
// Layout depends heavily on gfx, so we want to make sure that gfx is shut
1256-
// down after all the layout cleanup runs.
1256+
// Layout depends heavily on gfx and imagelib, so we want to make sure that
1257+
// these modules are shut down after all the layout cleanup runs.
1258+
mozilla::image::ShutdownModule();
12571259
gfxPlatform::Shutdown();
12581260
}
12591261

0 commit comments

Comments
 (0)