From 4102b2a1c86619a53eff0a585fd911826edd9b23 Mon Sep 17 00:00:00 2001 From: rfm Date: Sat, 12 Feb 2011 09:00:18 +0000 Subject: [PATCH] more changes to avoid leak warnings git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32093 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 96 +++++++++++-------- .../Additions/GNUstepBase/GSVersionMacros.h | 7 ++ Source/Additions/NSObject+GNUstepBase.m | 5 - Source/GSPrivate.h | 7 -- Source/NSConcreteMapTable.m | 4 +- Source/NSNotificationCenter.m | 12 +-- Source/NSPortCoder.m | 24 +---- Source/NSSerializer.m | 22 +---- Source/NSThread.m | 13 +-- 9 files changed, 70 insertions(+), 120 deletions(-) diff --git a/ChangeLog b/ChangeLog index 674c35e6d..d45a042e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-02-12 Richard Frith-Macdonald + + * Source/NSPortCoder.m: + * Source/GSPrivate.h: + * Source/NSNotificationCenter.m: + * Source/NSConcreteMapTable.m: + * Source/NSThread.m: + * Source/NSSerializer.m: + * Headers/Additions/GNUstepBase/GSVersionMacros.h: + Update with new GS_CONSUMED macro to try to avoid static analyzer + false positives. + 2011-02-12 Richard Frith-Macdonald * Source/NSLocale.m: fix memory leak @@ -27,7 +39,7 @@ 2011-02-11 Richard Frith-Macdonald - * libs/base/trunk/Source/GSPrivate.h: Fixed the new GS_BEGINITEMBUF() + * Source/GSPrivate.h: Fixed the new GS_BEGINITEMBUF() code ... was causing hard-to-track-down memory corruption which unfortunately didn't show up in the testsuite (or I'd not have re-comitted this code in the first place). @@ -80,7 +92,7 @@ 2011-02-11 12:06 David Chisnall - * libs/base/trunk/Source/GSPrivate.h: Added exception-safe version + * Source/GSPrivate.h: Added exception-safe version of the GS_BEGINITEMBUF() macro. As a side effect, this should silence the zero-sized VLA warnings in the static analyser. @@ -112,13 +124,13 @@ 2011-02-10 18:54 David Chisnall - * libs/base/trunk/config/config.joinable.m, - libs/base/trunk/config/objc-common.g: Don't use Object in + * trunk/config/config.joinable.m, + trunk/config/objc-common.g: Don't use Object in configure tests (not present in GNUstep runtime). 2011-02-10 18:53 David Chisnall - * libs/base/trunk/Source/NSObject.m: Use NSClassFromString() to + * Source/NSObject.m: Use NSClassFromString() to look up NSZombie class. This has two advantages: 1) Doesn't rely on Apple-incompatible behaviour in the GCC @@ -140,41 +152,41 @@ 2011-02-10 11:02 David Chisnall - * libs/base/trunk/Headers/Additions/GNUstepBase/GSMime.h, - libs/base/trunk/Headers/Additions/GNUstepBase/GSVersionMacros.h, - libs/base/trunk/Headers/Foundation/NSArchiver.h, - libs/base/trunk/Headers/Foundation/NSAutoreleasePool.h, - libs/base/trunk/Headers/Foundation/NSBundle.h, - libs/base/trunk/Headers/Foundation/NSCache.h, - libs/base/trunk/Headers/Foundation/NSComparisonPredicate.h, - libs/base/trunk/Headers/Foundation/NSDateFormatter.h, - libs/base/trunk/Headers/Foundation/NSDecimalNumber.h, - libs/base/trunk/Headers/Foundation/NSDistributedLock.h, - libs/base/trunk/Headers/Foundation/NSDistributedNotificationCenter.h, - libs/base/trunk/Headers/Foundation/NSError.h, - libs/base/trunk/Headers/Foundation/NSFileHandle.h, - libs/base/trunk/Headers/Foundation/NSFileManager.h, - libs/base/trunk/Headers/Foundation/NSHost.h, - libs/base/trunk/Headers/Foundation/NSIndexPath.h, - libs/base/trunk/Headers/Foundation/NSInvocation.h, - libs/base/trunk/Headers/Foundation/NSKeyedArchiver.h, - libs/base/trunk/Headers/Foundation/NSLocale.h, - libs/base/trunk/Headers/Foundation/NSNumberFormatter.h, - libs/base/trunk/Headers/Foundation/NSPort.h, - libs/base/trunk/Headers/Foundation/NSPortCoder.h, - libs/base/trunk/Headers/Foundation/NSPortMessage.h, - libs/base/trunk/Headers/Foundation/NSPortNameServer.h, - libs/base/trunk/Headers/Foundation/NSProtocolChecker.h, - libs/base/trunk/Headers/Foundation/NSRegularExpression.h, - libs/base/trunk/Headers/Foundation/NSScanner.h, - libs/base/trunk/Headers/Foundation/NSSortDescriptor.h, - libs/base/trunk/Headers/Foundation/NSTask.h, - libs/base/trunk/Headers/Foundation/NSThread.h, - libs/base/trunk/Headers/Foundation/NSTimer.h, - libs/base/trunk/Headers/Foundation/NSUndoManager.h, - libs/base/trunk/Headers/Foundation/NSUserDefaults.h, - libs/base/trunk/Headers/Foundation/NSXMLNode.h, - libs/base/trunk/Headers/Foundation/NSXMLParser.h: Add a + * Headers/Additions/GNUstepBase/GSMime.h, + Headers/Additions/GNUstepBase/GSVersionMacros.h, + Headers/Foundation/NSArchiver.h, + Headers/Foundation/NSAutoreleasePool.h, + Headers/Foundation/NSBundle.h, + Headers/Foundation/NSCache.h, + Headers/Foundation/NSComparisonPredicate.h, + Headers/Foundation/NSDateFormatter.h, + Headers/Foundation/NSDecimalNumber.h, + Headers/Foundation/NSDistributedLock.h, + Headers/Foundation/NSDistributedNotificationCenter.h, + Headers/Foundation/NSError.h, + Headers/Foundation/NSFileHandle.h, + Headers/Foundation/NSFileManager.h, + Headers/Foundation/NSHost.h, + Headers/Foundation/NSIndexPath.h, + Headers/Foundation/NSInvocation.h, + Headers/Foundation/NSKeyedArchiver.h, + Headers/Foundation/NSLocale.h, + Headers/Foundation/NSNumberFormatter.h, + Headers/Foundation/NSPort.h, + Headers/Foundation/NSPortCoder.h, + Headers/Foundation/NSPortMessage.h, + Headers/Foundation/NSPortNameServer.h, + Headers/Foundation/NSProtocolChecker.h, + Headers/Foundation/NSRegularExpression.h, + Headers/Foundation/NSScanner.h, + Headers/Foundation/NSSortDescriptor.h, + Headers/Foundation/NSTask.h, + Headers/Foundation/NSThread.h, + Headers/Foundation/NSTimer.h, + Headers/Foundation/NSUndoManager.h, + Headers/Foundation/NSUserDefaults.h, + Headers/Foundation/NSXMLNode.h, + Headers/Foundation/NSXMLParser.h: Add a GS_PADDING_IVAR macro. This defines the void *gs_unused; instance variable with __attribute__((unused)) on clang so that the static analyser only reports unused ivars that we expect to be used. @@ -328,7 +340,7 @@ 2011-01-23 15:42 David Chisnall - * libs/base/trunk/Source/NSNumberFormatter.m: Some small fixes in + * Source/NSNumberFormatter.m: Some small fixes in NSNumberFormatter. Mostly stop using == to compare C strings. 2011-01-23 Stefan Bidigaray @@ -480,7 +492,7 @@ 2010-12-31 14:03 David Chisnall - * libs/base/trunk/Headers/Foundation/NSBundle.h: Add __attribute__ + * Headers/Foundation/NSBundle.h: Add __attribute__ ((format_arg)) to [NSBundle -localizedStringForKey:value:table:]. This informs the compiler that the output can be used anywhere that the first argument can be used, and should silence all of diff --git a/Headers/Additions/GNUstepBase/GSVersionMacros.h b/Headers/Additions/GNUstepBase/GSVersionMacros.h index 4901ca167..6385e4e31 100644 --- a/Headers/Additions/GNUstepBase/GSVersionMacros.h +++ b/Headers/Additions/GNUstepBase/GSVersionMacros.h @@ -282,6 +282,13 @@ # endif #endif +#ifdef __clang__ +static inline void gs_consumed(id NS_CONSUMED o) __attribute __ ((unused)); +static inline void gs_consumed(id o) { return; } +#define GS_CONSUMED(O) gs_consumed(O); +#else +#define GS_CONSUMED(O) +#endif /* Include the appropriate header for ObjC2 blocks support if it is in use. * diff --git a/Source/Additions/NSObject+GNUstepBase.m b/Source/Additions/NSObject+GNUstepBase.m index 7a799dfad..46da2321a 100644 --- a/Source/Additions/NSObject+GNUstepBase.m +++ b/Source/Additions/NSObject+GNUstepBase.m @@ -122,8 +122,3 @@ @end -#ifdef __clang__ -#import "GSPrivate.h" -id gsPrivateDummy; -#endif - diff --git a/Source/GSPrivate.h b/Source/GSPrivate.h index b3f259c26..bfc72a41c 100644 --- a/Source/GSPrivate.h +++ b/Source/GSPrivate.h @@ -543,12 +543,5 @@ GSPrivateIsCollectable(const void *ptr) GS_ATTRIB_PRIVATE; NSZone* 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_ */ diff --git a/Source/NSConcreteMapTable.m b/Source/NSConcreteMapTable.m index f9b1423a0..b79981b82 100644 --- a/Source/NSConcreteMapTable.m +++ b/Source/NSConcreteMapTable.m @@ -525,8 +525,10 @@ NSEnumerateMapTable(NSMapTable *table) else { NSMapEnumerator v = {0, 0, 0}; + NSEnumerator *e = [[table keyEnumerator] retain]; - v.node = (void*)[[table keyEnumerator] retain]; + v.node = (void*)e; + GS_CONSUMED(e) v.bucket = (unsigned long)(uintptr_t)table; return v; } diff --git a/Source/NSNotificationCenter.m b/Source/NSNotificationCenter.m index 8f13643a1..486b0a28b 100644 --- a/Source/NSNotificationCenter.m +++ b/Source/NSNotificationCenter.m @@ -36,7 +36,6 @@ #import "Foundation/NSLock.h" #import "Foundation/NSThread.h" #import "GNUstepBase/GSLock.h" -#import "GSPrivate.h" static NSZone *_zone = 0; @@ -791,16 +790,7 @@ static NSNotificationCenter *default_center = nil; */ name = [name copyWithZone: NSDefaultMallocZone()]; 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 + GS_CONSUMED(name) } else { diff --git a/Source/NSPortCoder.m b/Source/NSPortCoder.m index 7a3b17c90..3fad79029 100644 --- a/Source/NSPortCoder.m +++ b/Source/NSPortCoder.m @@ -41,7 +41,6 @@ #import "Foundation/NSAutoreleasePool.h" #import "Foundation/NSData.h" #import "Foundation/NSPort.h" -#import "GSPrivate.h" @class NSMutableDataMalloc; @interface NSMutableDataMalloc : NSObject // Help the compiler @@ -617,17 +616,7 @@ static IMP _xRefImp; /* Serialize a crossref. */ obj = rep; 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 - + GS_CONSUMED(rep) } } *(id*)address = obj; @@ -735,16 +724,7 @@ static IMP _xRefImp; /* Serialize a crossref. */ */ address = &dummy; (*_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 + GS_CONSUMED(classInfo) } if (info != _GSC_NONE) { diff --git a/Source/NSSerializer.m b/Source/NSSerializer.m index f0bddd771..9c5c6d682 100644 --- a/Source/NSSerializer.m +++ b/Source/NSSerializer.m @@ -577,16 +577,7 @@ deserializeFromInfo(_NSDeserializerInfo* info) { 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 + GS_CONSUMED(s) return s; } @@ -623,16 +614,7 @@ deserializeFromInfo(_NSDeserializerInfo* info) { 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 + GS_CONSUMED(s) return s; } diff --git a/Source/NSThread.m b/Source/NSThread.m index 8f82fce07..36f25fac6 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -460,18 +460,7 @@ unregisterActiveThread(NSThread *thread) t = [self new]; t->_active = YES; 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 - + GS_CONSUMED(t); return YES; } return NO;