Subject: Re: bug#38618: 27.0.50; Mach port leak on macOS Catalina causing crash

From: Alan Third <[email-masked]>
Date: Tue, 17 Dec 2019 21:23:19 +0000

On Tue, Dec 17, 2019 at 12:49:07PM +0900, YAMAMOTO Mitsuharu wrote:
> 
> The Mac port (not the NS port in your report) also has the problem of
> Mach port leaks in -[NSWindow setRepresentedURL:] on macOS 10.15.  I
> think this is a bug in AppKit or some lower-level stuff.  I'll file it
> to Apple later.
> 
> I've installed a workaround into the "work" branch of the repository
> of the Mac port:
> 
>   https://bitbucket.org/mituharu/emacs-mac/commits/19c97087065b7ca64b71f392a453673042e024c6

Thank you for finding the problem!

Can someone on 10.15 try the attached patch, please?
-- 
Alan Third
>From 001657867ee189a4b06f790eb951fcdf0f65c732 Mon Sep 17 00:00:00 2001
From: Alan Third <[email-masked]>
Date: Tue, 17 Dec 2019 21:17:46 +0000
Subject: [PATCH] Check if file is in iCloud drive (bug#38618)

* src/nsfns.m (ns_set_represented_filename): Check whether the file is
a "ubiquitous item", and if so don't display a proxy icon.
---
 src/nsfns.m | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/nsfns.m b/src/nsfns.m
index 4c1fb76dea..1d3aea038a 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -490,6 +490,17 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   else
     fstr = @"";
 
+#if defined (NS_IMPL_COCOA) && defined (MAC_OS_X_VERSION_10_7)
+  /* Work around for Mach port leaks on macOS 10.15 (bug#38618).  */
+  NSURL *fileURL = [NSURL fileURLWithPath:fstr isDirectory:NO];
+  BOOL isUbiquitousItem = YES;
+  [fileURL getResourceValue:(id *)&isUbiquitousItem
+                     forKey:NSURLIsUbiquitousItemKey
+                      error:nil];
+  if (isUbiquitousItem)
+    fstr = @"";
+#endif
+
 #ifdef NS_IMPL_COCOA
   /* Work around a bug observed on 10.3 and later where
      setTitleWithRepresentedFilename does not clear out previous state
-- 
2.24.0