Skip to content

Commit c70dbf0

Browse files
committed
[Macros] Copy the evaluated source into an owned memory buffer.
Plugs a memory leak (rdar://103035316).
1 parent a2dfd90 commit c70dbf0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/Sema/TypeCheckMacros.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ Expr *swift::expandMacroExpr(
214214

215215
// Create a new source buffer with the contents of the expanded macro.
216216
auto macroBuffer =
217-
llvm::MemoryBuffer::getMemBuffer(evaluatedSource, bufferName);
217+
llvm::MemoryBuffer::getMemBufferCopy(evaluatedSource, bufferName);
218218
unsigned macroBufferID = sourceMgr.addNewSourceBuffer(std::move(macroBuffer));
219+
free((void*)evaluatedSource.data());
219220

220221
// Create a source file to hold the macro buffer. This is automatically
221222
// registered with the enclosing module.

0 commit comments

Comments
 (0)