]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix memory leaks in NS version.
authorJan Djärv <jan.h.d@swipnet.se>
Mon, 4 Nov 2013 17:57:17 +0000 (18:57 +0100)
committerJan Djärv <jan.h.d@swipnet.se>
Mon, 4 Nov 2013 17:57:17 +0000 (18:57 +0100)
* 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.

src/ChangeLog
src/macfont.m
src/nsfns.m
src/nsterm.h
src/nsterm.m

index e27f83962af7c3a4a5bc6b37edc824fc86b97abf..5f919b8516d81961d070e767d895176f6ef4b491 100644 (file)
@@ -1,3 +1,17 @@
+2013-11-04  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * 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  <eliz@gnu.org>
 
        * xdisp.c (message3_nolog, message_with_string): Encode the string
index 150aca0765114f30d9ab1075b2ea44c386795d5f..4b8be551786ac3ac9c5dd4961550738c57bb37ad 100644 (file)
@@ -624,19 +624,26 @@ get_cgcolor(unsigned long idx, struct frame *f)
 }
 
 #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)
 
 \f
 /* Mac font driver.  */
index 011edf38cef117e180dd396b3e10ee6d291183eb..c6730f41aa7100a0e6cd7741f424051b818d6bf3 100644 (file)
@@ -1194,6 +1194,7 @@ This function is an internal primitive--use `make-frame' instead.  */)
     x_default_parameter (f, parms, Qfont,
                                  build_string (fontname),
                                  "font", "Font", RES_TYPE_STRING);
+    xfree (fontname);
   }
   unblock_input ();
 
index 71faa075f325e074c2125c8020ef12f2ffb73b8a..22a8aec943669da4968670b481a2438593a75553 100644 (file)
@@ -85,6 +85,10 @@ typedef float EmacsCGFloat;
 /* 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;
index 5ca3ab7eed24252cee841541262732e41da70923..12f182968b3a1611f7340dbc9ee9dcd799b62544 100644 (file)
@@ -4367,6 +4367,46 @@ ns_term_shutdown (int sig)
 
 @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];