Attempts to prevent leak warnings from static analyser

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32090 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2011-02-12 06:51:42 +00:00
parent 3f94a2ef6b
commit c7bb84decb
9 changed files with 98 additions and 5 deletions

View file

@ -1,3 +1,15 @@
2011-02-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSLocale.m: fix memory leak
* Source/NSThread.m:
* Source/NSNotificationCenter.m:
* Source/NSPortCoder.m:
* Source/NSSerializer.m:
* Source/NSUserDefaults.m:
* Source/GSPrivate.h:
* Source/Additions/NSObject+GNUstepBase.m:
Add code to try to prevent clang static analyser false warnings.
2011-02-12 Richard Frith-Macdonald <rfm@gnu.org> 2011-02-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSPrivate.h: * Source/GSPrivate.h:

View file

@ -122,3 +122,8 @@
@end @end
#ifdef __clang__
#import "GSPrivate.h"
id gsPrivateDummy;
#endif

View file

@ -543,5 +543,12 @@ GSPrivateIsCollectable(const void *ptr) GS_ATTRIB_PRIVATE;
NSZone* NSZone*
GSAtomicMallocZone (void); GSAtomicMallocZone (void);
/* A global location to which we can assign objects in order to prevent
* the clang static analyser thinking we have leaked them when we haven't
*/
#ifdef __clang__
extern id gsPrivateDummy GS_ATTRIB_PRIVATE;
#endif
#endif /* _GSPrivate_h_ */ #endif /* _GSPrivate_h_ */

View file

@ -135,13 +135,17 @@ static NSLocaleLanguageDirection _ICUToNSLocaleOrientation (ULayoutType layout)
static NSArray *_currencyCodesWithType (uint32_t currType) static NSArray *_currencyCodesWithType (uint32_t currType)
{ {
NSArray *result; NSArray *result;
NSMutableArray *currencies = [[NSMutableArray alloc] initWithCapacity: 10]; NSMutableArray *currencies;
UErrorCode err = U_ZERO_ERROR; UErrorCode err = U_ZERO_ERROR;
const char *currCode; const char *currCode;
UEnumeration *codes = ucurr_openISOCurrencies (currType, &err); UEnumeration *codes;
codes = ucurr_openISOCurrencies (currType, &err);
if (U_FAILURE(err)) if (U_FAILURE(err))
return nil; return nil;
currencies = [[NSMutableArray alloc] initWithCapacity: 10];
do do
{ {
int strLength; int strLength;
@ -151,6 +155,7 @@ static NSArray *_currencyCodesWithType (uint32_t currType)
if (U_FAILURE(err)) if (U_FAILURE(err))
{ {
uenum_close (codes); uenum_close (codes);
[currencies release];
return nil; return nil;
} }
if (currCode == NULL) if (currCode == NULL)
@ -160,7 +165,7 @@ static NSArray *_currencyCodesWithType (uint32_t currType)
uenum_close (codes); uenum_close (codes);
result = [NSArray arrayWithArray: currencies]; result = [NSArray arrayWithArray: currencies];
RELEASE (currencies); [currencies release];
return result; return result;
} }
#endif #endif

View file

@ -790,6 +790,16 @@ static NSNotificationCenter *default_center = nil;
*/ */
name = [name copyWithZone: NSDefaultMallocZone()]; name = [name copyWithZone: NSDefaultMallocZone()];
GSIMapAddPair(NAMED, (GSIMapKey)(id)name, (GSIMapVal)(void*)m); GSIMapAddPair(NAMED, (GSIMapKey)(id)name, (GSIMapVal)(void*)m);
#ifdef __clang__
{
/* We store the object in 'dummy' for no other purpose than to silence
* the clang static analyser's warning that we are leaking memory, which
* occurs because it doesn't realise that the object was already stored
* later deallocation.
*/
gsPrivateDummy = name;
}
#endif
} }
else else
{ {

View file

@ -616,6 +616,17 @@ static IMP _xRefImp; /* Serialize a crossref. */
obj = rep; obj = rep;
GSIArraySetItemAtIndex(_objAry, (GSIArrayItem)obj, xref); GSIArraySetItemAtIndex(_objAry, (GSIArrayItem)obj, xref);
} }
#ifdef __clang__
{
/* We store the object in 'dummy' for no other purpose than to silence
* the clang static analyser's warning that we are leaking memory, which
* occurs because it doesn't realise that the object was already stored
* later deallocation.
*/
gsPrivateDummy = rep;
}
#endif
} }
} }
*(id*)address = obj; *(id*)address = obj;
@ -723,6 +734,16 @@ static IMP _xRefImp; /* Serialize a crossref. */
*/ */
address = &dummy; address = &dummy;
(*_dTagImp)(_src, dTagSel, &info, &xref, &_cursor); (*_dTagImp)(_src, dTagSel, &info, &xref, &_cursor);
#ifdef __clang__
{
/* We store the object in 'dummy' for no other purpose than to silence
* the clang static analyser's warning that we are leaking memory, which
* occurs because it doesn't realise that the object was already stored
* later deallocation.
*/
gsPrivateDummy = classInfo;
}
#endif
} }
if (info != _GSC_NONE) if (info != _GSC_NONE)
{ {

View file

@ -577,6 +577,16 @@ deserializeFromInfo(_NSDeserializerInfo* info)
{ {
GSIArrayAddItem(&info->array, (GSIArrayItem)((id)s)); GSIArrayAddItem(&info->array, (GSIArrayItem)((id)s));
} }
#ifdef __clang__
{
/* We store the object in 'dummy' for no other purpose than to silence
* the clang static analyser's warning that we are leaking memory, which
* occurs because it doesn't realise that the object was already stored
* later deallocation.
*/
gsPrivateDummy = s;
}
#endif
return s; return s;
} }
@ -613,6 +623,16 @@ deserializeFromInfo(_NSDeserializerInfo* info)
{ {
GSIArrayAddItem(&info->array, (GSIArrayItem)((id)s)); GSIArrayAddItem(&info->array, (GSIArrayItem)((id)s));
} }
#ifdef __clang__
{
/* We store the object in 'dummy' for no other purpose than to silence
* the clang static analyser's warning that we are leaking memory, which
* occurs because it doesn't realise that the object was already stored
* later deallocation.
*/
gsPrivateDummy = rep;
}
#endif
return s; return s;
} }

View file

@ -460,6 +460,18 @@ unregisterActiveThread(NSThread *thread)
t = [self new]; t = [self new];
t->_active = YES; t->_active = YES;
pthread_setspecific(thread_object_key, t); pthread_setspecific(thread_object_key, t);
#ifdef __clang__
{
/* We store the thread in 'dummy' for no other purpose than to silence
* the clang static analyser's warning that we are leaking memory, which
* occurs because it doesn't realise that pthread_setspecific() stores
* the thread for later deallocation.
*/
gsPrivateDummy = t;
}
#endif
return YES; return YES;
} }
return NO; return NO;

View file

@ -1925,7 +1925,7 @@ NSLog(@"Creating empty user defaults database");
enumerator = [_searchList reverseObjectEnumerator]; enumerator = [_searchList reverseObjectEnumerator];
nImp = [enumerator methodForSelector: nextObjectSel]; nImp = [enumerator methodForSelector: nextObjectSel];
dictRep = [NSMutableDictionaryClass allocWithZone: NSDefaultMallocZone()]; dictRep = [NSMutableDictionaryClass alloc];
dictRep = [dictRep initWithCapacity: 512]; dictRep = [dictRep initWithCapacity: 512];
addImp = [dictRep methodForSelector: addSel]; addImp = [dictRep methodForSelector: addSel];
@ -1937,7 +1937,8 @@ NSLog(@"Creating empty user defaults database");
(*addImp)(dictRep, addSel, dict); (*addImp)(dictRep, addSel, dict);
} }
} }
_dictionaryRep = [dictRep makeImmutableCopyOnFail: NO]; [dictRep makeImmutableCopyOnFail: NO];
_dictionaryRep = dictRep;
} }
rep = [[_dictionaryRep retain] autorelease]; rep = [[_dictionaryRep retain] autorelease];
[_lock unlock]; [_lock unlock];