Skip to content

Commit 8794df8

Browse files
committed
swift-inspect: correct invalid memory usage introduced in swiftlang#66973
Clean up the incorrect memory binding in swift-inspect introduced in PR#66973. This fixes the incorrect memory usage to mutate the `context` parameter.
1 parent e89de6e commit 8794df8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

tools/swift-inspect/Sources/swift-inspect/WindowsRemoteProcess.swift

+9-10
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,17 @@ internal final class WindowsRemoteProcess: RemoteProcess {
213213
}
214214

215215
var context: (DWORD64, String?) = (pSymbolInfo.pointee.ModBase, nil)
216-
_ = SymEnumerateModules64(
217-
self.process,
218-
{ ModuleName, BaseOfDll, UserContext in
219-
let pContext: UnsafeMutablePointer<(DWORD64, String?)> =
220-
UserContext!.bindMemory(to: (DWORD64, String?).self, capacity: 1)
221-
222-
if BaseOfDll == pContext.pointee.0 {
223-
pContext.pointee.1 = String(cString: ModuleName!)
224-
return false
216+
_ = withUnsafeMutablePointer(to: &context) {
217+
SymEnumerateModules64(self.process, { (ModuleName, BaseOfDll, UserContext) -> WindowsBool in
218+
if let pContext = UserContext?.bindMemory(to: (DWORD64, String?).self, capacity: 1) {
219+
if pContext.pointee.0 == BaseOfDll {
220+
pContext.pointee.1 = String(cString: ModuleName!)
221+
return false
222+
}
225223
}
226224
return true
227-
}, &context)
225+
}, $0)
226+
}
228227

229228
return (context.1, symbol)
230229
}

0 commit comments

Comments
 (0)