Skip to content

Commit 3d97980

Browse files
author
Nathan Hawes
committed
[sourcekitd] xpc_retain MainConnection so it remains valid for sending when cancelled from the other end
If a client crashes and we tried to post notifications to the XPC connection, SourceKitService would go down too, as it never `xpc_retain`ed the connection. Resolves rdar://problem/36077481
1 parent 501a176 commit 3d97980

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tools/SourceKit/tools/sourcekitd/bin/XPC/Service/XPCService.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ std::string sourcekitd::getRuntimeLibPath() {
209209
}
210210

211211
static void sourcekitdServer_peer_event_handler(xpc_connection_t peer,
212-
xpc_object_t event) {
212+
xpc_object_t event) {
213213
xpc_type_t type = xpc_get_type(event);
214214
if (type == XPC_TYPE_ERROR) {
215215
if (event == XPC_ERROR_CONNECTION_INVALID) {
@@ -305,6 +305,10 @@ static void sourcekitdServer_event_handler(xpc_connection_t peer) {
305305
sourcekitdServer_peer_event_handler(peer, event);
306306
});
307307

308+
// Update the main connection
309+
xpc_retain(peer);
310+
if (MainConnection)
311+
xpc_release(MainConnection);
308312
MainConnection = peer;
309313

310314
// This will tell the connection to begin listening for events. If you

0 commit comments

Comments
 (0)