Skip to content

Commit 0f96759

Browse files
authored
Merge pull request #2435 from compnerd/who-needs-memory
TSCBasic: plug a memory leak
2 parents 6b93a47 + 5e05fa5 commit 0f96759

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/TSCBasic/PathShims.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public func resolveSymlinks(_ path: AbsolutePath) -> AbsolutePath {
2828
// that implements readlink and not realpath.
2929
if let resultPtr = TSCLibc.realpath(pathStr, nil) {
3030
let result = String(cString: resultPtr)
31+
// If `resolved_path` is specified as NULL, then `realpath` uses
32+
// malloc(3) to allocate a buffer [...]. The caller should deallocate
33+
// this buffer using free(3).
34+
//
35+
// String.init(cString:) creates a new string by copying the
36+
// null-terminated UTF-8 data referenced by the given pointer.
37+
resultPtr.deallocate()
3138
// FIXME: We should measure if it's really more efficient to compare the strings first.
3239
return result == pathStr ? path : AbsolutePath(result)
3340
}

0 commit comments

Comments
 (0)