Skip to content

Commit a844f4f

Browse files
committed
Free memory allocated in Swift from Swift, not C++
1 parent 0c9a8a8 commit a844f4f

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

include/swift/Bridging/ASTGen.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ intptr_t swift_ASTGen_configuredRegions(
155155
BridgedASTContext astContext,
156156
void *_Nonnull sourceFile,
157157
BridgedIfConfigClauseRangeInfo *_Nullable *_Nonnull);
158+
void swift_ASTGen_freeConfiguredRegions(
159+
BridgedIfConfigClauseRangeInfo *_Nullable regions, intptr_t numRegions);
158160

159161
#ifdef __cplusplus
160162
}

lib/ASTGen/Sources/ASTGen/CompilerBuildConfiguration.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,11 @@ extension SyntaxProtocol {
275275
return false
276276
}
277277
}
278+
279+
@_cdecl("swift_ASTGen_freeConfiguredRegions")
280+
public func freeConfiguredRegions(
281+
regions: UnsafeMutablePointer<BridgedIfConfigClauseRangeInfo>?,
282+
numRegions: Int
283+
) {
284+
UnsafeMutableBufferPointer(start: regions, count: numRegions).deallocate()
285+
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3134,7 +3134,7 @@ ArrayRef<IfConfigClauseRangeInfo> SourceFile::getIfConfigClauseRanges() const {
31343134
IfConfigClauseRanges.Ranges.reserve(numRegions);
31353135
for (intptr_t i = 0; i != numRegions; ++i)
31363136
IfConfigClauseRanges.Ranges.push_back(regions[i].unbridged());
3137-
free(regions);
3137+
swift_ASTGen_freeConfiguredRegions(regions, numRegions);
31383138

31393139
IfConfigClauseRanges.IsSorted = true;
31403140
}

0 commit comments

Comments
 (0)