Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: src/IceGlobalContext.cpp

Issue 1181013016: Subzero. Fixes memory leaks. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: clang-format: for f in $(git diff --name-only HEAD~7); do if [[ ${f} == *h || ${f} == *cpp ]]; then… Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/IceGlobalContext.cpp
diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
index b23e75b83e4e5e31e6f8a5d999e03a0de8511349..fd0a3b7eb0b214e8c288cfdc3267b7c5d09138a6 100644
--- a/src/IceGlobalContext.cpp
+++ b/src/IceGlobalContext.cpp
@@ -224,8 +224,7 @@ GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError,
// EmitQ is allowed unlimited size.
EmitQ(/*Sequential=*/Flags.isSequential()),
DataLowering(TargetDataLowering::createLowering(this)),
- HasSeenCode(false),
- ProfileBlockInfoVarDecl(VariableDeclaration::create()) {
+ HasSeenCode(false) {
assert(OsDump && "OsDump is not defined for GlobalContext");
assert(OsEmit && "OsEmit is not defined for GlobalContext");
assert(OsError && "OsError is not defined for GlobalContext");
@@ -257,6 +256,11 @@ GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError,
case FT_Iasm:
break;
}
+
+ // ProfileBlockInfoVarDecl is initialized here because it takes this as a
+ // parameter -- we want to
+ // ensure that at least this' member variables are initialized.
+ ProfileBlockInfoVarDecl = VariableDeclaration::create(this);
ProfileBlockInfoVarDecl->setAlignment(typeWidthInBytes(IceType_i64));
ProfileBlockInfoVarDecl->setIsConstant(true);
@@ -339,7 +343,7 @@ void addBlockInfoPtrs(const VariableDeclarationList &Globals,
if (Cfg::isProfileGlobal(*Global)) {
constexpr RelocOffsetT BlockExecutionCounterOffset = 0;
ProfileBlockInfo->addInitializer(
- new VariableDeclaration::RelocInitializer(
+ VariableDeclaration::RelocInitializer::create(
Global, BlockExecutionCounterOffset));
}
}
@@ -364,9 +368,7 @@ void GlobalContext::emitFileHeader() {
}
}
-void GlobalContext::lowerConstants() {
- DataLowering->lowerConstants();
-}
+void GlobalContext::lowerConstants() { DataLowering->lowerConstants(); }
void GlobalContext::lowerGlobals(const IceString &SectionSuffix) {
TimerMarker T(TimerStack::TT_emitGlobalInitializers, this);
@@ -382,20 +384,28 @@ void GlobalContext::lowerGlobals(const IceString &SectionSuffix) {
if (Flags.getDisableTranslation())
return;
- addBlockInfoPtrs(Globals, ProfileBlockInfoVarDecl.get());
+ addBlockInfoPtrs(Globals, ProfileBlockInfoVarDecl);
DataLowering->lowerGlobals(Globals, SectionSuffix);
+ for (VariableDeclaration *Var : Globals) {
+ Var->discardInitializers();
+ }
Globals.clear();
}
void GlobalContext::lowerProfileData() {
+ // ProfileBlockInfoVarDecl is initialized in the constructor, and will only
+ // ever be nullptr after this method completes. This assertion is a convoluted
+ // way of ensuring lowerProfileData is invoked a single time.
+ assert(ProfileBlockInfoVarDecl != nullptr);
// This adds a 64-bit sentinel entry to the end of our array. For 32-bit
// architectures this will waste 4 bytes.
const SizeT Sizeof64BitNullPtr = typeWidthInBytes(IceType_i64);
ProfileBlockInfoVarDecl->addInitializer(
- new VariableDeclaration::ZeroInitializer(Sizeof64BitNullPtr));
- Globals.push_back(ProfileBlockInfoVarDecl.get());
+ VariableDeclaration::ZeroInitializer::create(Sizeof64BitNullPtr));
+ Globals.push_back(ProfileBlockInfoVarDecl);
constexpr char ProfileDataSection[] = "$sz_profiler$";
lowerGlobals(ProfileDataSection);
+ ProfileBlockInfoVarDecl = nullptr;
}
void GlobalContext::emitItems() {
@@ -644,6 +654,12 @@ IceString GlobalContext::mangleName(const IceString &Name) const {
GlobalContext::~GlobalContext() {
llvm::DeleteContainerPointers(AllThreadContexts);
+ LockedPtr<DestructorArray> Dtors = getDestructors();
+ // Destructors are invoked in the opposite object construction order.
+ for (auto DtorIter = Dtors->crbegin(); DtorIter != Dtors->crend();
+ ++DtorIter) {
+ (*DtorIter)();
+ }
}
// TODO(stichnot): Consider adding thread-local caches of constant

Powered by Google App Engine
This is Rietveld 408576698