From cfce9b418072ff930d400890dcc0781e919fce24 Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Wed, 4 Oct 2017 22:02:53 +0200 Subject: Fix potential leak in macspellimp.mm + avoid macSpell var I'm not sure to retrieve [NSSpellChecker sharedSpellChecker] in a pointer is a good idea. Most of the examples using sharedSpellChecker just call [NSSpellChecker sharedSpellChecker] each time. If there's a bit more code, at least we're sure we won't leak because of this. Change-Id: I9818bd3d51f26b50849e1a5e69cc705acd92ad29 Reviewed-on: https://gerrit.libreoffice.org/43140 Tested-by: Jenkins Reviewed-by: Julien Nabet --- lingucomponent/source/spellcheck/macosxspell/macspellimp.hxx | 1 - lingucomponent/source/spellcheck/macosxspell/macspellimp.mm | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'lingucomponent') diff --git a/lingucomponent/source/spellcheck/macosxspell/macspellimp.hxx b/lingucomponent/source/spellcheck/macosxspell/macspellimp.hxx index 7c72b748c7b2..c489bee337f2 100644 --- a/lingucomponent/source/spellcheck/macosxspell/macspellimp.hxx +++ b/lingucomponent/source/spellcheck/macosxspell/macspellimp.hxx @@ -63,7 +63,6 @@ class MacSpellChecker : Locale * aDLocs; OUString * aDNames; sal_Int32 numdict; - NSSpellChecker * macSpell; int macTag; // unique tag for this doc ::comphelper::OInterfaceContainerHelper2 aEvtListeners; diff --git a/lingucomponent/source/spellcheck/macosxspell/macspellimp.mm b/lingucomponent/source/spellcheck/macosxspell/macspellimp.mm index f146db7b8dab..4519e2a98fd7 100644 --- a/lingucomponent/source/spellcheck/macosxspell/macspellimp.mm +++ b/lingucomponent/source/spellcheck/macosxspell/macspellimp.mm @@ -57,7 +57,6 @@ MacSpellChecker::MacSpellChecker() : numdict = 0; NSApplicationLoad(); NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - macSpell = [NSSpellChecker sharedSpellChecker]; macTag = [NSSpellChecker uniqueSpellDocumentTag]; [pool release]; } @@ -117,7 +116,7 @@ Sequence< Locale > SAL_CALL MacSpellChecker::getLocales() for (NSUInteger i = 0; i < [aLocales count]; i++) { NSString* pLangStr = (NSString*)[aLocales objectAtIndex:i]; - if( [macSpell setLanguage:pLangStr ] ) + if( [[NSSpellChecker sharedSpellChecker] setLanguage:pLangStr ] ) { postspdict.push_back( pLangStr ); } @@ -241,7 +240,7 @@ sal_Int16 MacSpellChecker::GetSpellFailure( const OUString &rWord, const Locale } NSInteger aCount; - NSRange range = [macSpell checkSpellingOfString:aNSStr startingAt:0 language:aLang wrap:false inSpellDocumentWithTag:macTag wordCount:&aCount]; + NSRange range = [[NSSpellChecker sharedSpellChecker] checkSpellingOfString:aNSStr startingAt:0 language:aLang wrap:false inSpellDocumentWithTag:macTag wordCount:&aCount]; int rVal = 0; if(range.length>0) { @@ -339,8 +338,8 @@ Reference< XSpellAlternatives > NSString* aTaggedCountry = [@"_" stringByAppendingString:aCountry]; aLang = [aLang stringByAppendingString:aTaggedCountry]; } - [macSpell setLanguage:aLang]; - NSArray *guesses = [macSpell guessesForWordRange:NSMakeRange(0, [aNSStr length]) inString:aNSStr language:aLang inSpellDocumentWithTag:0]; + [[NSSpellChecker sharedSpellChecker] setLanguage:aLang]; + NSArray *guesses = [[NSSpellChecker sharedSpellChecker] guessesForWordRange:NSMakeRange(0, [aNSStr length]) inString:aNSStr language:aLang inSpellDocumentWithTag:0]; count = [guesses count]; if (count) { -- cgit