[PATCH] D88497: [objc] Fix memory leak in CGObjCMac.cpp
Ellis Hoag via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 29 08:40:01 PDT 2020
ellis created this revision.
ellis added a reviewer: rjmccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ellis requested review of this revision.
A memory leak was introduced in https://reviews.llvm.org/D88329
CGObjCMac.cpp was leaking a MangleContext everytime it mangled
an ObjC method. We now have an instance variable that allocates
and deallocates the context.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88497
Files:
clang/lib/CodeGen/CGObjCMac.cpp
Index: clang/lib/CodeGen/CGObjCMac.cpp
===================================================================
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1079,8 +1079,9 @@
void EmitImageInfo();
public:
- CGObjCCommonMac(CodeGen::CodeGenModule &cgm) :
- CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()) { }
+ CGObjCCommonMac(CodeGen::CodeGenModule &cgm)
+ : CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()),
+ Mangler(cgm.getContext().createMangleContext()) {}
bool isNonFragileABI() const {
return ObjCABI == 2;
@@ -1121,6 +1122,7 @@
private:
void fillRunSkipBlockVars(CodeGenModule &CGM, const CGBlockInfo &blockInfo);
+ std::unique_ptr<MangleContext> Mangler;
};
namespace {
@@ -4003,9 +4005,8 @@
} else {
SmallString<256> Name;
llvm::raw_svector_ostream OS(Name);
- const auto &MC = CGM.getContext().createMangleContext();
- MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
- /*includeCategoryNamespace=*/true);
+ Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+ /*includeCategoryNamespace=*/true);
CodeGenTypes &Types = CGM.getTypes();
llvm::FunctionType *MethodTy =
@@ -4059,9 +4060,8 @@
} else {
SmallString<256> Name;
llvm::raw_svector_ostream OS(Name);
- const auto &MC = CGM.getContext().createMangleContext();
- MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
- /*includeCategoryNamespace=*/false);
+ Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+ /*includeCategoryNamespace=*/false);
Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
Name.str(), &CGM.getModule());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88497.295007.patch
Type: text/x-patch
Size: 1866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200929/12e75709/attachment.bin>
More information about the cfe-commits
mailing list