Hi Richard,

I'd like to backport this change to 2.1.x. 
This is another attempt to fix tickets like #8637.
http://www.lyx.org/trac/ticket/8637

Is it ok?

Stephan

Am 09.10.2015 um 10:07 schrieb Stephan Witt <sw...@lyx.org>:

> commit 989c72530e789abf234cca5e6084e585cc073bb6
> Author: Stephan Witt <sw...@lyx.org>
> Date:   Fri Oct 9 08:16:10 2015 +0200
> 
>    Avoid the use of a static NSAutoreleasePool.
>    This seems to cause crashes on exit from time to time.
> 
> diff --git a/src/support/linkback/LinkBackProxy.m 
> b/src/support/linkback/LinkBackProxy.m
> index 0f6b71d..e676c68 100644
> --- a/src/support/linkback/LinkBackProxy.m
> +++ b/src/support/linkback/LinkBackProxy.m
> @@ -16,8 +16,6 @@
> 
> ///////////////////////////////////////////////////////////////////////
> 
> -static NSAutoreleasePool * pool = nil;
> -
> @interface LyXLinkBackClient : NSObject <LinkBackClientDelegate> {
>       NSMutableSet * keys;
> }
> @@ -173,42 +171,32 @@ static NSAutoreleasePool * pool = nil;
> 
> static LyXLinkBackClient * linkBackClient = nil;
> 
> -void checkAutoReleasePool()
> -{
> -     if (pool == nil)
> -             pool = [[NSAutoreleasePool alloc] init];
> -}
> -
> int isLinkBackDataInPasteboard()
> {
> -     checkAutoReleasePool() ;
> -     {
> -             NSArray * linkBackType = [NSArray arrayWithObjects: 
> LinkBackPboardType, nil];
> -             NSString * ret = [[NSPasteboard generalPasteboard] 
> availableTypeFromArray:linkBackType];
> -             return ret != nil;
> -     }
> +     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
> +     NSArray * linkBackType = [NSArray arrayWithObjects: LinkBackPboardType, 
> nil];
> +     NSString * ret = [[NSPasteboard generalPasteboard] 
> availableTypeFromArray:linkBackType];
> +     [pool release];
> +     return ret != nil;
> }
> 
> 
> void getLinkBackData(void const * * buf, unsigned * len)
> {
> -     checkAutoReleasePool() ;
> -     {
> -             // get linkback data from pasteboard
> -             NSPasteboard * pboard = [NSPasteboard generalPasteboard];
> -             id linkBackData = [pboard 
> propertyListForType:LinkBackPboardType];
> +     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
> +     // get linkback data from pasteboard
> +     NSPasteboard * pboard = [NSPasteboard generalPasteboard];
> +     id linkBackData = [pboard propertyListForType:LinkBackPboardType];
>               
> -             NSData * nsdata
> -             = [NSArchiver archivedDataWithRootObject:linkBackData];
> -             if (nsdata == nil) {
> -                     *buf = 0;
> -                     *len = 0;
> -                     return;
> -             }
> -
> +     NSData * nsdata = [NSArchiver archivedDataWithRootObject:linkBackData];
> +     if (nsdata == nil) {
> +             *buf = 0;
> +             *len = 0;
> +     } else {
>               *buf = [nsdata bytes];
>               *len = [nsdata length];
>       }
> +     [pool release];
> }
> 
> 
> @@ -217,11 +205,12 @@ int editLinkBackFile(char const * docName)
>       // setup Obj-C and our client
>       if (linkBackClient == nil)
>               linkBackClient = [[LyXLinkBackClient alloc] init];
> -     checkAutoReleasePool() ;
> -     
> +     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
>       // FIXME: really UTF8 here?
>       NSString * nsDocName = [NSString stringWithUTF8String:docName];
> -     return [linkBackClient edit:nsDocName] == YES;
> +     int result = [linkBackClient edit:nsDocName] == YES;
> +     [pool release];
> +     return result;
> }
> 
> 
> @@ -231,10 +220,5 @@ void closeAllLinkBackLinks()
>               [linkBackClient release];
>               linkBackClient = nil;
>       }
> -
> -     if (pool != nil) {
> -             [pool drain];
> -             pool = nil;
> -     }
> }
> 

Reply via email to