emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r114945: Fix memory leaks in NS version.


From: Jan D.
Subject: [Emacs-diffs] trunk r114945: Fix memory leaks in NS version.
Date: Mon, 04 Nov 2013 17:57:23 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114945
revision-id: address@hidden
parent: address@hidden
committer: Jan Djärv <address@hidden>
branch nick: trunk
timestamp: Mon 2013-11-04 18:57:17 +0100
message:
  Fix memory leaks in NS version.
  
  * src/macfont.m (CG_SET_FILL_COLOR_WITH_GC_FOREGROUND)
  (CG_SET_FILL_COLOR_WITH_GC_BACKGROUND)
  (CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND): Fix memory leak.
  
  * src/nsfns.m (Fx_create_frame): Fix memory leak.
  
  * src/nsterm.h (EmacsApp): Add shouldKeepRunning and isFirst for
  OSX >= 10.9.
  
  * src/nsterm.m (init, run, stop:): New methods in EmacsApp for
  OSX >= 10.9 to prevent memory leak of GCD dispatch source.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/macfont.m                  macfont.m-20130915173740-04lgloz0557bz98l-2
  src/nsfns.m                    nsfns.m-20091113204419-o5vbwnq5f7feedwu-8741
  src/nsterm.h                   nsterm.h-20091113204419-o5vbwnq5f7feedwu-8746
  src/nsterm.m                   nsterm.m-20091113204419-o5vbwnq5f7feedwu-8747
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-11-04 17:33:43 +0000
+++ b/src/ChangeLog     2013-11-04 17:57:17 +0000
@@ -1,3 +1,17 @@
+2013-11-04  Jan Djärv  <address@hidden>
+
+       * nsterm.m (init, run, stop:): New methods in EmacsApp for
+       OSX >= 10.9 to prevent memory leak of GCD dispatch source.
+
+       * nsterm.h (EmacsApp): Add shouldKeepRunning and isFirst for
+       OSX >= 10.9.
+
+       * nsfns.m (Fx_create_frame): Fix memory leak.
+
+       * macfont.m (CG_SET_FILL_COLOR_WITH_GC_FOREGROUND)
+       (CG_SET_FILL_COLOR_WITH_GC_BACKGROUND)
+       (CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND): Fix memory leak.
+
 2013-11-04  Eli Zaretskii  <address@hidden>
 
        * xdisp.c (message3_nolog, message_with_string): Encode the string

=== modified file 'src/macfont.m'
--- a/src/macfont.m     2013-10-25 06:55:36 +0000
+++ b/src/macfont.m     2013-11-04 17:57:17 +0000
@@ -624,19 +624,26 @@
 }
 
 #define CG_SET_FILL_COLOR_WITH_GC_FOREGROUND(context, s)                \
-  CGContextSetFillColorWithColor (context,                              \
-                                  get_cgcolor (NS_FACE_FOREGROUND (s->face), \
-                                               s->f))
-
+  do {                                                                  \
+    CGColorRef refcol_ = get_cgcolor (NS_FACE_FOREGROUND (s->face),     \
+                                      s->f);                            \
+    CGContextSetFillColorWithColor (context, refcol_) ;                 \
+    CGColorRelease (refcol_);                                           \
+  } while (0)
 #define CG_SET_FILL_COLOR_WITH_GC_BACKGROUND(context, s)                \
-  CGContextSetFillColorWithColor (context,                              \
-                                  get_cgcolor (NS_FACE_BACKGROUND (s->face), \
-                                               s->f))
-
+  do {                                                                  \
+    CGColorRef refcol_ = get_cgcolor (NS_FACE_BACKGROUND (s->face),\
+                                      s->f);                            \
+    CGContextSetFillColorWithColor (context, refcol_);                  \
+    CGColorRelease (refcol_);                                           \
+  } while (0)
 #define CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND(context, s)              \
-  CGContextSetStrokeColorWithColor (context,                            \
-                                    get_cgcolor (NS_FACE_FOREGROUND (s->face),\
-                                                 s->f))
+  do {                                                                  \
+    CGColorRef refcol_ = get_cgcolor (NS_FACE_FOREGROUND (s->face),\
+                                      s->f);                            \
+    CGContextSetStrokeColorWithColor (context, refcol_);                \
+    CGColorRelease (refcol_);                                           \
+  } while (0)
 
 
 /* Mac font driver.  */

=== modified file 'src/nsfns.m'
--- a/src/nsfns.m       2013-10-18 12:57:44 +0000
+++ b/src/nsfns.m       2013-11-04 17:57:17 +0000
@@ -1194,6 +1194,7 @@
     x_default_parameter (f, parms, Qfont,
                                  build_string (fontname),
                                  "font", "Font", RES_TYPE_STRING);
+    xfree (fontname);
   }
   unblock_input ();
 

=== modified file 'src/nsterm.h'
--- a/src/nsterm.h      2013-10-18 12:57:44 +0000
+++ b/src/nsterm.h      2013-11-04 17:57:17 +0000
@@ -85,6 +85,10 @@
 /* We override sendEvent: as a means to stop/start the event loop */
 @interface EmacsApp : NSApplication
 {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
+  BOOL shouldKeepRunning;
+  BOOL isFirst;
+#endif
 #ifdef NS_IMPL_GNUSTEP
 @public
   int nextappdefined;

=== modified file 'src/nsterm.m'
--- a/src/nsterm.m      2013-10-20 09:55:25 +0000
+++ b/src/nsterm.m      2013-11-04 17:57:17 +0000
@@ -4367,6 +4367,46 @@
 
 @implementation EmacsApp
 
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
+- (id)init
+{
+  if (self = [super init])
+    self->isFirst = YES;
+
+  return self;
+}
+
+- (void)run
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+    if (isFirst) [self finishLaunching];
+    isFirst = NO;
+
+    shouldKeepRunning = YES;
+    do
+    {
+        [pool release];
+        pool = [[NSAutoreleasePool alloc] init];
+
+        NSEvent *event =
+          [self nextEventMatchingMask:NSAnyEventMask
+                            untilDate:[NSDate distantFuture]
+                               inMode:NSDefaultRunLoopMode
+                              dequeue:YES];
+        [self sendEvent:event];
+        [self updateWindows];
+    } while (shouldKeepRunning);
+
+    [pool release];
+}
+
+- (void)stop: (id)sender
+{
+    shouldKeepRunning = NO;
+}
+#endif
+
 - (void)logNotification: (NSNotification *)notification
 {
   const char *name = [[notification name] UTF8String];


reply via email to

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