Skip to content

Commit 0ae2906

Browse files
committed
Use MallocAllocator Allocate/Deallocate consistently.
Buyer beware: the `MallocAllocator` does not, in fact, use `malloc`, so one cannot pair an allocation using `MallocAllocator` with an actual `free`.
1 parent ab44d47 commit 0ae2906

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/AST/CASTBridging.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ using namespace swift;
1717

1818
namespace {
1919
struct BridgedDiagnosticImpl {
20+
typedef llvm::MallocAllocator Allocator;
21+
2022
InFlightDiagnostic inFlight;
2123
std::vector<StringRef> textBlobs;
2224

@@ -31,8 +33,10 @@ struct BridgedDiagnosticImpl {
3133

3234
~BridgedDiagnosticImpl() {
3335
inFlight.flush();
36+
37+
Allocator allocator;
3438
for (auto text : textBlobs) {
35-
free((void *)text.data());
39+
allocator.Deallocate(text.data(), text.size());
3640
}
3741
}
3842
};
@@ -100,8 +104,8 @@ BridgedDiagnostic Diagnostic_create(BridgedDiagnosticEngine cDiags,
100104
BridgedSourceLoc cLoc,
101105
BridgedString cText) {
102106
StringRef origText = convertString(cText);
103-
llvm::MallocAllocator mallocAlloc;
104-
StringRef text = origText.copy(mallocAlloc);
107+
BridgedDiagnosticImpl::Allocator alloc;
108+
StringRef text = origText.copy(alloc);
105109

106110
SourceLoc loc = convertSourceLoc(cLoc);
107111

@@ -148,8 +152,8 @@ void Diagnostic_fixItReplace(BridgedDiagnostic cDiag,
148152
SourceLoc endLoc = convertSourceLoc(cEndLoc);
149153

150154
StringRef origReplaceText = convertString(cReplaceText);
151-
llvm::MallocAllocator mallocAlloc;
152-
StringRef replaceText = origReplaceText.copy(mallocAlloc);
155+
BridgedDiagnosticImpl::Allocator alloc;
156+
StringRef replaceText = origReplaceText.copy(alloc);
153157

154158
BridgedDiagnosticImpl *diag = convertDiagnostic(cDiag);
155159
diag->textBlobs.push_back(replaceText);

0 commit comments

Comments
 (0)