emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r106709: Fix biggest memory leaks in


From: Jan D.
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r106709: Fix biggest memory leaks in NS-port. More remain.
Date: Wed, 21 Dec 2011 09:04:19 +0100
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 106709
committer: Jan D. <address@hidden>
branch nick: trunk
timestamp: Wed 2011-12-21 09:04:19 +0100
message:
  Fix biggest memory leaks in NS-port.  More remain.
  
  * emacs.c (ns_pool): New variable.
  (main): Assign ns_pool.
  (Fkill_emacs): Call ns_release_autorelease_pool.
  
  * nsfns.m (x_set_background_color): Assign return value from
  ns_index_color to face-background instead of NSColor*.
  (ns_implicitly_set_icon_type): Fix indentation.
  Change assignment in for loop to comparison.
  
  * nsfont.m (ns_spec_to_descriptor): Fix indentation,
  autorelease fdesc, release fdAttrs and tdict.
  (ns_get_covering_families): Release charset.
  (ns_findfonts): Release NSFontDescriptor created with new.
  (ns_uni_to_glyphs): Fix indentation.
  (setString): Release attrStr before assigning new value.
  
  * nsmenu.m (ns_update_menubar): Call free_menubar_widget_value_tree
  before returning.
  
  * nsterm.m (x_free_frame_resources): Release
  f->output_data.ns->miniimage
  (ns_index_color): Fix indentation.  Do not retain
  color_table->colors[i].
modified:
  src/ChangeLog
  src/emacs.c
  src/nsfns.m
  src/nsfont.m
  src/nsmenu.m
  src/nsterm.m
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2011-12-21 06:37:49 +0000
+++ b/src/ChangeLog     2011-12-21 08:04:19 +0000
@@ -1,3 +1,29 @@
+2011-12-21  Jan Djärv  <address@hidden>
+
+       * nsterm.m (x_free_frame_resources): Release
+       f->output_data.ns->miniimage
+       (ns_index_color): Fix indentation.  Do not retain
+       color_table->colors[i].
+
+       * nsmenu.m (ns_update_menubar): Call free_menubar_widget_value_tree
+       before returning.
+
+       * nsfns.m (x_set_background_color): Assign return value from
+       ns_index_color to face-background instead of NSColor*.
+       (ns_implicitly_set_icon_type): Fix indentation.
+       Change assignment in for loop to comparison.
+
+       * emacs.c (ns_pool): New variable.
+       (main): Assign ns_pool.
+       (Fkill_emacs): Call ns_release_autorelease_pool.
+
+       * nsfont.m (ns_spec_to_descriptor): Fix indentation,
+       autorelease fdesc, release fdAttrs and tdict.
+       (ns_get_covering_families): Release charset.
+       (ns_findfonts): Release NSFontDescriptor created with new.
+       (ns_uni_to_glyphs): Fix indentation.
+       (setString): Release attrStr before assigning new value.
+
 2011-12-18  Jan Djärv  <address@hidden>
 
        * nsmenu.m (NSMenuDidBeginTrackingNotification): Declare if OSX < 10.5

=== modified file 'src/emacs.c'
--- a/src/emacs.c       2011-12-12 05:32:49 +0000
+++ b/src/emacs.c       2011-12-21 08:04:19 +0000
@@ -321,6 +321,12 @@
 pthread_t main_thread;
 #endif
 
+#ifdef HAVE_NS
+/* NS autrelease pool, for memory management.  */
+static void *ns_pool;
+#endif  
+
+ 
 
 /* Handle bus errors, invalid instruction, etc.  */
 #ifndef FLOAT_CATCH_SIGILL
@@ -1318,7 +1324,7 @@
     = argmatch (argv, argc, "-nsl", "--no-site-lisp", 11, NULL, &skip_args);
 
 #ifdef HAVE_NS
-  ns_alloc_autorelease_pool ();
+  ns_pool = ns_alloc_autorelease_pool ();
   if (!noninteractive)
     {
 #ifdef NS_IMPL_COCOA
@@ -2015,6 +2021,10 @@
 
   shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
 
+#ifdef HAVE_NS
+  ns_release_autorelease_pool (ns_pool);
+#endif
+
   /* If we have an auto-save list file,
      kill it because we are exiting Emacs deliberately (not crashing).
      Do it after shut_down_emacs, which does an auto-save.  */

=== modified file 'src/nsfns.m'
--- a/src/nsfns.m       2011-12-10 14:01:08 +0000
+++ b/src/nsfns.m       2011-12-21 08:04:19 +0000
@@ -394,9 +394,8 @@
       if (face)
         {
           col = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f);
-          face->background
-            = (EMACS_UINT) [[col colorWithAlphaComponent: alpha] retain];
-          [col release];
+          face->background = ns_index_color
+            ([col colorWithAlphaComponent: alpha], f);
 
           update_face_from_frame_parameter (f, Qbackground_color, arg);
         }
@@ -770,7 +769,7 @@
 {
   Lisp_Object tem;
   EmacsView *view = FRAME_NS_VIEW (f);
-  id image =nil;
+  id image = nil;
   Lisp_Object chain, elt;
   NSAutoreleasePool *pool;
   BOOL setMini = YES;
@@ -797,7 +796,7 @@
     }
 
   for (chain = Vns_icon_type_alist;
-       (image = nil) && CONSP (chain);
+       image == nil && CONSP (chain);
        chain = XCDR (chain))
     {
       elt = XCAR (chain);

=== modified file 'src/nsfont.m'
--- a/src/nsfont.m      2011-12-12 05:32:49 +0000
+++ b/src/nsfont.m      2011-12-21 08:04:19 +0000
@@ -126,8 +126,8 @@
 /* Converts FONT_WEIGHT, FONT_SLANT, FONT_WIDTH, plus family and script/lang
    to NSFont descriptor.  Information under extra only needed for matching. */
 #define STYLE_REF 100
-static NSFontDescriptor
-*ns_spec_to_descriptor(Lisp_Object font_spec)
+static NSFontDescriptor *
+ns_spec_to_descriptor (Lisp_Object font_spec)
 {
     NSFontDescriptor *fdesc;
     NSMutableDictionary *fdAttrs = [NSMutableDictionary new];
@@ -152,8 +152,14 @@
        [fdAttrs setObject: tdict forKey: NSFontTraitsAttribute];
 
     fdesc = [NSFontDescriptor fontDescriptorWithFontAttributes: fdAttrs];
-    if (family != nil)
+    if (family != nil) 
+      {
        fdesc = [fdesc fontDescriptorWithFamily: family];
+        [fdesc autorelease];
+      }
+
+    [fdAttrs release];
+    [tdict release];
     return fdesc;
 }
 
@@ -469,6 +475,7 @@
                if ([families count] > 0 || pct < 0.05)
                    break;
              }
+            [charset release];
          }
 #ifdef NS_IMPL_COCOA
        if ([families count] == 0)
@@ -536,12 +543,14 @@
     family = [fdesc objectForKey: NSFontFamilyAttribute];
     if (family != nil && !foundItal && XINT (Flength (list)) > 0)
       {
-       NSFontDescriptor *sDesc = [[[NSFontDescriptor new]
-           fontDescriptorWithSymbolicTraits: NSFontItalicTrait]
-           fontDescriptorWithFamily: family];
+        NSFontDescriptor *s1 = [NSFontDescriptor new];
+        NSFontDescriptor *sDesc
+          = [[s1 fontDescriptorWithSymbolicTraits: NSFontItalicTrait]
+              fontDescriptorWithFamily: family];
        list = Fcons (ns_descriptor_to_entity (sDesc,
                                         AREF (font_spec, FONT_EXTRA_INDEX),
                                         "synthItal"), list);
+        [s1 release];
       }
 
     /* Return something if was a match and nothing found. */
@@ -1293,7 +1302,7 @@
     abort ();
 
   /* create a string containing all Unicode characters in this block */
-  for (idx = block<<8, i =0; i<0x100; idx++, i++)
+  for (idx = block<<8, i = 0; i < 0x100; idx++, i++)
     if (idx < 0xD800 || idx > 0xDFFF)
       unichars[i] = idx;
     else
@@ -1309,7 +1318,7 @@
     NSGlyphGenerator *glyphGenerator = [NSGlyphGenerator sharedGlyphGenerator];
     /*NSCharacterSet *coveredChars = [nsfont coveredCharacterSet]; */
     unsigned int numGlyphs = [font_info->nsfont numberOfGlyphs];
-    NSUInteger gInd =0, cInd =0;
+    NSUInteger gInd = 0, cInd = 0;
 
     [glyphStorage setString: allChars font: font_info->nsfont];
     [glyphGenerator generateGlyphsForGlyphStorage: glyphStorage
@@ -1317,7 +1326,7 @@
                                        glyphIndex: &gInd characterIndex: 
&cInd];
 #endif
     glyphs = font_info->glyphs[block];
-    for (i =0; i<0x100; i++, glyphs++)
+    for (i = 0; i < 0x100; i++, glyphs++)
       {
 #ifdef NS_IMPL_GNUSTEP
         g = unichars[i];
@@ -1425,6 +1434,8 @@
 - (void) setString: (NSString *)str font: (NSFont *)font
 {
   [dict setObject: font forKey: NSFontAttributeName];
+  if (attrStr != nil)
+    [attrStr release];
   attrStr = [[NSAttributedString alloc] initWithString: str attributes: dict];
   maxChar = [str length];
   maxGlyph = 0;

=== modified file 'src/nsmenu.m'
--- a/src/nsmenu.m      2011-12-18 14:50:19 +0000
+++ b/src/nsmenu.m      2011-12-21 08:04:19 +0000
@@ -404,6 +404,7 @@
       items = FRAME_MENU_BAR_ITEMS (f);
       if (NILP (items))
         {
+          free_menubar_widget_value_tree (first_wv);
           [pool release];
           UNBLOCK_INPUT;
           return;
@@ -431,6 +432,7 @@
 
           if (i == n)
             {
+              free_menubar_widget_value_tree (first_wv);
               [pool release];
               UNBLOCK_INPUT;
               return;

=== modified file 'src/nsterm.m'
--- a/src/nsterm.m      2011-12-18 14:50:19 +0000
+++ b/src/nsterm.m      2011-12-21 08:04:19 +0000
@@ -1158,6 +1158,9 @@
 
   xfree (f->output_data.ns);
 
+  if (f->output_data.ns->miniimage != nil)
+    [f->output_data.ns->miniimage release];
+
   [[view window] close];
   [view release];
 
@@ -1351,7 +1354,7 @@
 {
   struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table;
   ptrdiff_t idx;
-  NSNumber *index;
+  ptrdiff_t i;
 
   if (!color_table->colors)
     {
@@ -1364,21 +1367,13 @@
     }
 
   /* do we already have this color ? */
-  {
-    ptrdiff_t i;
-    for (i = 1; i < color_table->avail; i++)
-      {
-        if (color_table->colors[i] && [color_table->colors[i] isEqual: color])
-          {
-            [color_table->colors[i] retain];
-            return i;
-          }
-      }
-  }
+  for (i = 1; i < color_table->avail; i++)
+    if (color_table->colors[i] && [color_table->colors[i] isEqual: color])
+      return i;
 
   if ([color_table->empty_indices count] > 0)
     {
-      index = [color_table->empty_indices anyObject];
+      NSNumber *index = [color_table->empty_indices anyObject];
       [color_table->empty_indices removeObject: index];
       idx = [index unsignedLongValue];
     }
@@ -1411,20 +1406,20 @@
   color_table = FRAME_NS_DISPLAY_INFO (f)->color_table;
 
   if (idx <= 0 || idx >= color_table->size) {
-    message1("ns_free_indexed_color: Color index out of range.\n");
+    message1 ("ns_free_indexed_color: Color index out of range.\n");
     return;
   }
 
   index = [NSNumber numberWithUnsignedInt: idx];
   if ([color_table->empty_indices containsObject: index]) {
-    message1("ns_free_indexed_color: attempt to free already freed color.\n");
+    message1 ("ns_free_indexed_color: attempt to free already freed color.\n");
     return;
   }
 
   color = color_table->colors[idx];
   [color release];
   color_table->colors[idx] = nil;
-  [color_table->empty_indices addObject: [NSNumber numberWithUnsignedInt: 
idx]];
+  [color_table->empty_indices addObject: index];
 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
 }
 


reply via email to

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