Skip to content

Commit 49ed912

Browse files
committed
Close DLHandle if initializing sourcekitd fails
1 parent a7585dc commit 49ed912

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Sources/SourceKitD/DynamicallyLoadedSourceKitD.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,17 @@ package actor DynamicallyLoadedSourceKitD: SourceKitD {
118118
let dlopenModes: DLOpenFlags = [.lazy, .local, .first]
119119
#endif
120120
let dlhandle = try dlopen(path.filePath, mode: dlopenModes)
121-
try self.init(
122-
dlhandle: dlhandle,
123-
path: path,
124-
pluginPaths: pluginPaths,
125-
initialize: initialize
126-
)
121+
do {
122+
try self.init(
123+
dlhandle: dlhandle,
124+
path: path,
125+
pluginPaths: pluginPaths,
126+
initialize: initialize
127+
)
128+
} catch {
129+
try? dlhandle.close()
130+
throw error
131+
}
127132
}
128133

129134
package init(dlhandle: DLHandle, path: URL, pluginPaths: PluginPaths?, initialize: Bool) throws {

0 commit comments

Comments
 (0)