emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master d0a2543: Plug NS memory leaks (bug#45502)


From: Mattias Engdegård
Subject: master d0a2543: Plug NS memory leaks (bug#45502)
Date: Wed, 30 Dec 2020 05:36:28 -0500 (EST)

branch: master
commit d0a254398609262dc5e6960655a7818f21a24447
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Plug NS memory leaks (bug#45502)
    
    * src/nsmenu.m ([EmacsMenu addItemWithWidgetValue:attributes:]):
    Mark allocated and owned objects for autorelease.
---
 src/nsmenu.m | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/nsmenu.m b/src/nsmenu.m
index ac36150..de0c61c 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -481,7 +481,7 @@ skipspc (const char *s)
       if (title == nil)
         title = @"< ? >";  /* (get out in the open so we know about it) */
 
-      item = [[NSMenuItem alloc] init];
+      item = [[[NSMenuItem alloc] init] autorelease];
       if (wv->key)
         {
           NSString *key = [NSString stringWithUTF8String: skipspc (wv->key)];
@@ -495,9 +495,10 @@ skipspc (const char *s)
 #endif
         }
 
-      NSAttributedString *atitle = [[NSAttributedString alloc]
+      NSAttributedString *atitle = [[[NSAttributedString alloc]
                                          initWithString: title
-                                             attributes: attributes];
+                                             attributes: attributes]
+                                     autorelease];
       [item setAction: @selector (menuDown:)];
       [item setAttributedTitle: atitle];
       [item setEnabled: wv->enabled];
@@ -542,7 +543,7 @@ skipspc (const char *s)
   NSDictionary *attributes = nil;
 
 #ifdef NS_IMPL_COCOA
-  /* Cocoa doesn't allow multi-key chording in its menu display, so
+  /* Cocoa doesn't allow multi-key sequences in its menu display, so
      work around it by using tabs to split the title into two
      columns.  */
   NSDictionary *font_attribs = @{NSFontAttributeName: menuFont};
@@ -570,8 +571,8 @@ skipspc (const char *s)
   /* Set a right-aligned tab stop at the maximum width, so that the
      key will appear immediately to the left of it. */
   NSTextTab *tab =
-    [[[NSTextTab alloc] initWithTextAlignment: NSTextAlignmentRight
-                                     location: maxWidth
+    [[[NSTextTab alloc] initWithTextAlignment: NSTextAlignmentLeft
+                                     location: maxWidth - maxKeyWidth
                                       options: @{}] autorelease];
   NSMutableParagraphStyle *pstyle = [[[NSMutableParagraphStyle alloc] init]
                                       autorelease];



reply via email to

[Prev in Thread] Current Thread [Next in Thread]