aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2011-12-21 09:04:19 +0100
committerJan Djärv2011-12-21 09:04:19 +0100
commit204ee57fa0bb286ba4c6f540cefb44ed011a921f (patch)
treead3751bd5677a04fb731108cdeaaf74ca55d05bb /src
parentbc86f573eecb9067dfb73c612309a909332bb15d (diff)
downloademacs-204ee57fa0bb286ba4c6f540cefb44ed011a921f.tar.gz
emacs-204ee57fa0bb286ba4c6f540cefb44ed011a921f.zip
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].
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog26
-rw-r--r--src/emacs.c12
-rw-r--r--src/nsfns.m9
-rw-r--r--src/nsfont.m29
-rw-r--r--src/nsmenu.m2
-rw-r--r--src/nsterm.m27
6 files changed, 74 insertions, 31 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 673d6fb9d97..e40a7f3fbe0 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,29 @@
12011-12-21 Jan Djärv <jan.h.d@swipnet.se>
2
3 * nsterm.m (x_free_frame_resources): Release
4 f->output_data.ns->miniimage
5 (ns_index_color): Fix indentation. Do not retain
6 color_table->colors[i].
7
8 * nsmenu.m (ns_update_menubar): Call free_menubar_widget_value_tree
9 before returning.
10
11 * nsfns.m (x_set_background_color): Assign return value from
12 ns_index_color to face-background instead of NSColor*.
13 (ns_implicitly_set_icon_type): Fix indentation.
14 Change assignment in for loop to comparison.
15
16 * emacs.c (ns_pool): New variable.
17 (main): Assign ns_pool.
18 (Fkill_emacs): Call ns_release_autorelease_pool.
19
20 * nsfont.m (ns_spec_to_descriptor): Fix indentation,
21 autorelease fdesc, release fdAttrs and tdict.
22 (ns_get_covering_families): Release charset.
23 (ns_findfonts): Release NSFontDescriptor created with new.
24 (ns_uni_to_glyphs): Fix indentation.
25 (setString): Release attrStr before assigning new value.
26
12011-12-18 Jan Djärv <jan.h.d@swipnet.se> 272011-12-18 Jan Djärv <jan.h.d@swipnet.se>
2 28
3 * nsmenu.m (NSMenuDidBeginTrackingNotification): Declare if OSX < 10.5 29 * nsmenu.m (NSMenuDidBeginTrackingNotification): Declare if OSX < 10.5
diff --git a/src/emacs.c b/src/emacs.c
index 12a48b26553..f4fa0eb0b9e 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -321,6 +321,12 @@ static void (*fatal_error_signal_hook) (void);
321pthread_t main_thread; 321pthread_t main_thread;
322#endif 322#endif
323 323
324#ifdef HAVE_NS
325/* NS autrelease pool, for memory management. */
326static void *ns_pool;
327#endif
328
329
324 330
325/* Handle bus errors, invalid instruction, etc. */ 331/* Handle bus errors, invalid instruction, etc. */
326#ifndef FLOAT_CATCH_SIGILL 332#ifndef FLOAT_CATCH_SIGILL
@@ -1318,7 +1324,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1318 = argmatch (argv, argc, "-nsl", "--no-site-lisp", 11, NULL, &skip_args); 1324 = argmatch (argv, argc, "-nsl", "--no-site-lisp", 11, NULL, &skip_args);
1319 1325
1320#ifdef HAVE_NS 1326#ifdef HAVE_NS
1321 ns_alloc_autorelease_pool (); 1327 ns_pool = ns_alloc_autorelease_pool ();
1322 if (!noninteractive) 1328 if (!noninteractive)
1323 { 1329 {
1324#ifdef NS_IMPL_COCOA 1330#ifdef NS_IMPL_COCOA
@@ -2015,6 +2021,10 @@ all of which are called before Emacs is actually killed. */)
2015 2021
2016 shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil); 2022 shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
2017 2023
2024#ifdef HAVE_NS
2025 ns_release_autorelease_pool (ns_pool);
2026#endif
2027
2018 /* If we have an auto-save list file, 2028 /* If we have an auto-save list file,
2019 kill it because we are exiting Emacs deliberately (not crashing). 2029 kill it because we are exiting Emacs deliberately (not crashing).
2020 Do it after shut_down_emacs, which does an auto-save. */ 2030 Do it after shut_down_emacs, which does an auto-save. */
diff --git a/src/nsfns.m b/src/nsfns.m
index 9dade071e85..e41b77e242a 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -394,9 +394,8 @@ x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
394 if (face) 394 if (face)
395 { 395 {
396 col = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f); 396 col = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f);
397 face->background 397 face->background = ns_index_color
398 = (EMACS_UINT) [[col colorWithAlphaComponent: alpha] retain]; 398 ([col colorWithAlphaComponent: alpha], f);
399 [col release];
400 399
401 update_face_from_frame_parameter (f, Qbackground_color, arg); 400 update_face_from_frame_parameter (f, Qbackground_color, arg);
402 } 401 }
@@ -770,7 +769,7 @@ ns_implicitly_set_icon_type (struct frame *f)
770{ 769{
771 Lisp_Object tem; 770 Lisp_Object tem;
772 EmacsView *view = FRAME_NS_VIEW (f); 771 EmacsView *view = FRAME_NS_VIEW (f);
773 id image =nil; 772 id image = nil;
774 Lisp_Object chain, elt; 773 Lisp_Object chain, elt;
775 NSAutoreleasePool *pool; 774 NSAutoreleasePool *pool;
776 BOOL setMini = YES; 775 BOOL setMini = YES;
@@ -797,7 +796,7 @@ ns_implicitly_set_icon_type (struct frame *f)
797 } 796 }
798 797
799 for (chain = Vns_icon_type_alist; 798 for (chain = Vns_icon_type_alist;
800 (image = nil) && CONSP (chain); 799 image == nil && CONSP (chain);
801 chain = XCDR (chain)) 800 chain = XCDR (chain))
802 { 801 {
803 elt = XCAR (chain); 802 elt = XCAR (chain);
diff --git a/src/nsfont.m b/src/nsfont.m
index 6a053af344d..080af447b0a 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -126,8 +126,8 @@ ns_attribute_fvalue (NSFontDescriptor *fdesc, NSString *trait)
126/* Converts FONT_WEIGHT, FONT_SLANT, FONT_WIDTH, plus family and script/lang 126/* Converts FONT_WEIGHT, FONT_SLANT, FONT_WIDTH, plus family and script/lang
127 to NSFont descriptor. Information under extra only needed for matching. */ 127 to NSFont descriptor. Information under extra only needed for matching. */
128#define STYLE_REF 100 128#define STYLE_REF 100
129static NSFontDescriptor 129static NSFontDescriptor *
130*ns_spec_to_descriptor(Lisp_Object font_spec) 130ns_spec_to_descriptor (Lisp_Object font_spec)
131{ 131{
132 NSFontDescriptor *fdesc; 132 NSFontDescriptor *fdesc;
133 NSMutableDictionary *fdAttrs = [NSMutableDictionary new]; 133 NSMutableDictionary *fdAttrs = [NSMutableDictionary new];
@@ -152,8 +152,14 @@ static NSFontDescriptor
152 [fdAttrs setObject: tdict forKey: NSFontTraitsAttribute]; 152 [fdAttrs setObject: tdict forKey: NSFontTraitsAttribute];
153 153
154 fdesc = [NSFontDescriptor fontDescriptorWithFontAttributes: fdAttrs]; 154 fdesc = [NSFontDescriptor fontDescriptorWithFontAttributes: fdAttrs];
155 if (family != nil) 155 if (family != nil)
156 {
156 fdesc = [fdesc fontDescriptorWithFamily: family]; 157 fdesc = [fdesc fontDescriptorWithFamily: family];
158 [fdesc autorelease];
159 }
160
161 [fdAttrs release];
162 [tdict release];
157 return fdesc; 163 return fdesc;
158} 164}
159 165
@@ -469,6 +475,7 @@ static NSSet
469 if ([families count] > 0 || pct < 0.05) 475 if ([families count] > 0 || pct < 0.05)
470 break; 476 break;
471 } 477 }
478 [charset release];
472 } 479 }
473#ifdef NS_IMPL_COCOA 480#ifdef NS_IMPL_COCOA
474 if ([families count] == 0) 481 if ([families count] == 0)
@@ -536,12 +543,14 @@ ns_findfonts (Lisp_Object font_spec, BOOL isMatch)
536 family = [fdesc objectForKey: NSFontFamilyAttribute]; 543 family = [fdesc objectForKey: NSFontFamilyAttribute];
537 if (family != nil && !foundItal && XINT (Flength (list)) > 0) 544 if (family != nil && !foundItal && XINT (Flength (list)) > 0)
538 { 545 {
539 NSFontDescriptor *sDesc = [[[NSFontDescriptor new] 546 NSFontDescriptor *s1 = [NSFontDescriptor new];
540 fontDescriptorWithSymbolicTraits: NSFontItalicTrait] 547 NSFontDescriptor *sDesc
541 fontDescriptorWithFamily: family]; 548 = [[s1 fontDescriptorWithSymbolicTraits: NSFontItalicTrait]
549 fontDescriptorWithFamily: family];
542 list = Fcons (ns_descriptor_to_entity (sDesc, 550 list = Fcons (ns_descriptor_to_entity (sDesc,
543 AREF (font_spec, FONT_EXTRA_INDEX), 551 AREF (font_spec, FONT_EXTRA_INDEX),
544 "synthItal"), list); 552 "synthItal"), list);
553 [s1 release];
545 } 554 }
546 555
547 /* Return something if was a match and nothing found. */ 556 /* Return something if was a match and nothing found. */
@@ -1293,7 +1302,7 @@ ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block)
1293 abort (); 1302 abort ();
1294 1303
1295 /* create a string containing all Unicode characters in this block */ 1304 /* create a string containing all Unicode characters in this block */
1296 for (idx = block<<8, i =0; i<0x100; idx++, i++) 1305 for (idx = block<<8, i = 0; i < 0x100; idx++, i++)
1297 if (idx < 0xD800 || idx > 0xDFFF) 1306 if (idx < 0xD800 || idx > 0xDFFF)
1298 unichars[i] = idx; 1307 unichars[i] = idx;
1299 else 1308 else
@@ -1309,7 +1318,7 @@ ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block)
1309 NSGlyphGenerator *glyphGenerator = [NSGlyphGenerator sharedGlyphGenerator]; 1318 NSGlyphGenerator *glyphGenerator = [NSGlyphGenerator sharedGlyphGenerator];
1310 /*NSCharacterSet *coveredChars = [nsfont coveredCharacterSet]; */ 1319 /*NSCharacterSet *coveredChars = [nsfont coveredCharacterSet]; */
1311 unsigned int numGlyphs = [font_info->nsfont numberOfGlyphs]; 1320 unsigned int numGlyphs = [font_info->nsfont numberOfGlyphs];
1312 NSUInteger gInd =0, cInd =0; 1321 NSUInteger gInd = 0, cInd = 0;
1313 1322
1314 [glyphStorage setString: allChars font: font_info->nsfont]; 1323 [glyphStorage setString: allChars font: font_info->nsfont];
1315 [glyphGenerator generateGlyphsForGlyphStorage: glyphStorage 1324 [glyphGenerator generateGlyphsForGlyphStorage: glyphStorage
@@ -1317,7 +1326,7 @@ ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block)
1317 glyphIndex: &gInd characterIndex: &cInd]; 1326 glyphIndex: &gInd characterIndex: &cInd];
1318#endif 1327#endif
1319 glyphs = font_info->glyphs[block]; 1328 glyphs = font_info->glyphs[block];
1320 for (i =0; i<0x100; i++, glyphs++) 1329 for (i = 0; i < 0x100; i++, glyphs++)
1321 { 1330 {
1322#ifdef NS_IMPL_GNUSTEP 1331#ifdef NS_IMPL_GNUSTEP
1323 g = unichars[i]; 1332 g = unichars[i];
@@ -1425,6 +1434,8 @@ ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block)
1425- (void) setString: (NSString *)str font: (NSFont *)font 1434- (void) setString: (NSString *)str font: (NSFont *)font
1426{ 1435{
1427 [dict setObject: font forKey: NSFontAttributeName]; 1436 [dict setObject: font forKey: NSFontAttributeName];
1437 if (attrStr != nil)
1438 [attrStr release];
1428 attrStr = [[NSAttributedString alloc] initWithString: str attributes: dict]; 1439 attrStr = [[NSAttributedString alloc] initWithString: str attributes: dict];
1429 maxChar = [str length]; 1440 maxChar = [str length];
1430 maxGlyph = 0; 1441 maxGlyph = 0;
diff --git a/src/nsmenu.m b/src/nsmenu.m
index d599cdb6ce5..94c6b6a6198 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -404,6 +404,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
404 items = FRAME_MENU_BAR_ITEMS (f); 404 items = FRAME_MENU_BAR_ITEMS (f);
405 if (NILP (items)) 405 if (NILP (items))
406 { 406 {
407 free_menubar_widget_value_tree (first_wv);
407 [pool release]; 408 [pool release];
408 UNBLOCK_INPUT; 409 UNBLOCK_INPUT;
409 return; 410 return;
@@ -431,6 +432,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
431 432
432 if (i == n) 433 if (i == n)
433 { 434 {
435 free_menubar_widget_value_tree (first_wv);
434 [pool release]; 436 [pool release];
435 UNBLOCK_INPUT; 437 UNBLOCK_INPUT;
436 return; 438 return;
diff --git a/src/nsterm.m b/src/nsterm.m
index 055959bf2ac..f8e69f98942 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1158,6 +1158,9 @@ x_free_frame_resources (struct frame *f)
1158 1158
1159 xfree (f->output_data.ns); 1159 xfree (f->output_data.ns);
1160 1160
1161 if (f->output_data.ns->miniimage != nil)
1162 [f->output_data.ns->miniimage release];
1163
1161 [[view window] close]; 1164 [[view window] close];
1162 [view release]; 1165 [view release];
1163 1166
@@ -1351,7 +1354,7 @@ ns_index_color (NSColor *color, struct frame *f)
1351{ 1354{
1352 struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table; 1355 struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table;
1353 ptrdiff_t idx; 1356 ptrdiff_t idx;
1354 NSNumber *index; 1357 ptrdiff_t i;
1355 1358
1356 if (!color_table->colors) 1359 if (!color_table->colors)
1357 { 1360 {
@@ -1364,21 +1367,13 @@ ns_index_color (NSColor *color, struct frame *f)
1364 } 1367 }
1365 1368
1366 /* do we already have this color ? */ 1369 /* do we already have this color ? */
1367 { 1370 for (i = 1; i < color_table->avail; i++)
1368 ptrdiff_t i; 1371 if (color_table->colors[i] && [color_table->colors[i] isEqual: color])
1369 for (i = 1; i < color_table->avail; i++) 1372 return i;
1370 {
1371 if (color_table->colors[i] && [color_table->colors[i] isEqual: color])
1372 {
1373 [color_table->colors[i] retain];
1374 return i;
1375 }
1376 }
1377 }
1378 1373
1379 if ([color_table->empty_indices count] > 0) 1374 if ([color_table->empty_indices count] > 0)
1380 { 1375 {
1381 index = [color_table->empty_indices anyObject]; 1376 NSNumber *index = [color_table->empty_indices anyObject];
1382 [color_table->empty_indices removeObject: index]; 1377 [color_table->empty_indices removeObject: index];
1383 idx = [index unsignedLongValue]; 1378 idx = [index unsignedLongValue];
1384 } 1379 }
@@ -1411,20 +1406,20 @@ ns_free_indexed_color (unsigned long idx, struct frame *f)
1411 color_table = FRAME_NS_DISPLAY_INFO (f)->color_table; 1406 color_table = FRAME_NS_DISPLAY_INFO (f)->color_table;
1412 1407
1413 if (idx <= 0 || idx >= color_table->size) { 1408 if (idx <= 0 || idx >= color_table->size) {
1414 message1("ns_free_indexed_color: Color index out of range.\n"); 1409 message1 ("ns_free_indexed_color: Color index out of range.\n");
1415 return; 1410 return;
1416 } 1411 }
1417 1412
1418 index = [NSNumber numberWithUnsignedInt: idx]; 1413 index = [NSNumber numberWithUnsignedInt: idx];
1419 if ([color_table->empty_indices containsObject: index]) { 1414 if ([color_table->empty_indices containsObject: index]) {
1420 message1("ns_free_indexed_color: attempt to free already freed color.\n"); 1415 message1 ("ns_free_indexed_color: attempt to free already freed color.\n");
1421 return; 1416 return;
1422 } 1417 }
1423 1418
1424 color = color_table->colors[idx]; 1419 color = color_table->colors[idx];
1425 [color release]; 1420 [color release];
1426 color_table->colors[idx] = nil; 1421 color_table->colors[idx] = nil;
1427 [color_table->empty_indices addObject: [NSNumber numberWithUnsignedInt: idx]]; 1422 [color_table->empty_indices addObject: index];
1428/*fprintf(stderr, "color_table: FREED %d\n",idx);*/ 1423/*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1429} 1424}
1430 1425