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
This commit is contained in:
rfm 2011-02-12 09:00:18 +00:00
parent 453c7fcb1e
commit 4102b2a1c8
9 changed files with 70 additions and 120 deletions

View file

@ -1,3 +1,15 @@
2011-02-12 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <rfm@gnu.org> 2011-02-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSLocale.m: fix memory leak * Source/NSLocale.m: fix memory leak
@ -27,7 +39,7 @@
2011-02-11 Richard Frith-Macdonald <rfm@gnu.org> 2011-02-11 Richard Frith-Macdonald <rfm@gnu.org>
* 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 code ... was causing hard-to-track-down memory corruption which
unfortunately didn't show up in the testsuite (or I'd not have unfortunately didn't show up in the testsuite (or I'd not have
re-comitted this code in the first place). re-comitted this code in the first place).
@ -80,7 +92,7 @@
2011-02-11 12:06 David Chisnall <theraven@gna.org> 2011-02-11 12:06 David Chisnall <theraven@gna.org>
* 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 of the GS_BEGINITEMBUF() macro. As a side effect, this should
silence the zero-sized VLA warnings in the static analyser. silence the zero-sized VLA warnings in the static analyser.
@ -112,13 +124,13 @@
2011-02-10 18:54 David Chisnall <theraven@gna.org> 2011-02-10 18:54 David Chisnall <theraven@gna.org>
* libs/base/trunk/config/config.joinable.m, * trunk/config/config.joinable.m,
libs/base/trunk/config/objc-common.g: Don't use Object in trunk/config/objc-common.g: Don't use Object in
configure tests (not present in GNUstep runtime). configure tests (not present in GNUstep runtime).
2011-02-10 18:53 David Chisnall <theraven@gna.org> 2011-02-10 18:53 David Chisnall <theraven@gna.org>
* libs/base/trunk/Source/NSObject.m: Use NSClassFromString() to * Source/NSObject.m: Use NSClassFromString() to
look up NSZombie class. This has two advantages: look up NSZombie class. This has two advantages:
1) Doesn't rely on Apple-incompatible behaviour in the GCC 1) Doesn't rely on Apple-incompatible behaviour in the GCC
@ -140,41 +152,41 @@
2011-02-10 11:02 David Chisnall <theraven@gna.org> 2011-02-10 11:02 David Chisnall <theraven@gna.org>
* libs/base/trunk/Headers/Additions/GNUstepBase/GSMime.h, * Headers/Additions/GNUstepBase/GSMime.h,
libs/base/trunk/Headers/Additions/GNUstepBase/GSVersionMacros.h, Headers/Additions/GNUstepBase/GSVersionMacros.h,
libs/base/trunk/Headers/Foundation/NSArchiver.h, Headers/Foundation/NSArchiver.h,
libs/base/trunk/Headers/Foundation/NSAutoreleasePool.h, Headers/Foundation/NSAutoreleasePool.h,
libs/base/trunk/Headers/Foundation/NSBundle.h, Headers/Foundation/NSBundle.h,
libs/base/trunk/Headers/Foundation/NSCache.h, Headers/Foundation/NSCache.h,
libs/base/trunk/Headers/Foundation/NSComparisonPredicate.h, Headers/Foundation/NSComparisonPredicate.h,
libs/base/trunk/Headers/Foundation/NSDateFormatter.h, Headers/Foundation/NSDateFormatter.h,
libs/base/trunk/Headers/Foundation/NSDecimalNumber.h, Headers/Foundation/NSDecimalNumber.h,
libs/base/trunk/Headers/Foundation/NSDistributedLock.h, Headers/Foundation/NSDistributedLock.h,
libs/base/trunk/Headers/Foundation/NSDistributedNotificationCenter.h, Headers/Foundation/NSDistributedNotificationCenter.h,
libs/base/trunk/Headers/Foundation/NSError.h, Headers/Foundation/NSError.h,
libs/base/trunk/Headers/Foundation/NSFileHandle.h, Headers/Foundation/NSFileHandle.h,
libs/base/trunk/Headers/Foundation/NSFileManager.h, Headers/Foundation/NSFileManager.h,
libs/base/trunk/Headers/Foundation/NSHost.h, Headers/Foundation/NSHost.h,
libs/base/trunk/Headers/Foundation/NSIndexPath.h, Headers/Foundation/NSIndexPath.h,
libs/base/trunk/Headers/Foundation/NSInvocation.h, Headers/Foundation/NSInvocation.h,
libs/base/trunk/Headers/Foundation/NSKeyedArchiver.h, Headers/Foundation/NSKeyedArchiver.h,
libs/base/trunk/Headers/Foundation/NSLocale.h, Headers/Foundation/NSLocale.h,
libs/base/trunk/Headers/Foundation/NSNumberFormatter.h, Headers/Foundation/NSNumberFormatter.h,
libs/base/trunk/Headers/Foundation/NSPort.h, Headers/Foundation/NSPort.h,
libs/base/trunk/Headers/Foundation/NSPortCoder.h, Headers/Foundation/NSPortCoder.h,
libs/base/trunk/Headers/Foundation/NSPortMessage.h, Headers/Foundation/NSPortMessage.h,
libs/base/trunk/Headers/Foundation/NSPortNameServer.h, Headers/Foundation/NSPortNameServer.h,
libs/base/trunk/Headers/Foundation/NSProtocolChecker.h, Headers/Foundation/NSProtocolChecker.h,
libs/base/trunk/Headers/Foundation/NSRegularExpression.h, Headers/Foundation/NSRegularExpression.h,
libs/base/trunk/Headers/Foundation/NSScanner.h, Headers/Foundation/NSScanner.h,
libs/base/trunk/Headers/Foundation/NSSortDescriptor.h, Headers/Foundation/NSSortDescriptor.h,
libs/base/trunk/Headers/Foundation/NSTask.h, Headers/Foundation/NSTask.h,
libs/base/trunk/Headers/Foundation/NSThread.h, Headers/Foundation/NSThread.h,
libs/base/trunk/Headers/Foundation/NSTimer.h, Headers/Foundation/NSTimer.h,
libs/base/trunk/Headers/Foundation/NSUndoManager.h, Headers/Foundation/NSUndoManager.h,
libs/base/trunk/Headers/Foundation/NSUserDefaults.h, Headers/Foundation/NSUserDefaults.h,
libs/base/trunk/Headers/Foundation/NSXMLNode.h, Headers/Foundation/NSXMLNode.h,
libs/base/trunk/Headers/Foundation/NSXMLParser.h: Add a Headers/Foundation/NSXMLParser.h: Add a
GS_PADDING_IVAR macro. This defines the void *gs_unused; instance GS_PADDING_IVAR macro. This defines the void *gs_unused; instance
variable with __attribute__((unused)) on clang so that the static variable with __attribute__((unused)) on clang so that the static
analyser only reports unused ivars that we expect to be used. analyser only reports unused ivars that we expect to be used.
@ -328,7 +340,7 @@
2011-01-23 15:42 David Chisnall <theraven@gna.org> 2011-01-23 15:42 David Chisnall <theraven@gna.org>
* 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. NSNumberFormatter. Mostly stop using == to compare C strings.
2011-01-23 Stefan Bidigaray <stefanbidi@gmail.com> 2011-01-23 Stefan Bidigaray <stefanbidi@gmail.com>
@ -480,7 +492,7 @@
2010-12-31 14:03 David Chisnall <theraven@gna.org> 2010-12-31 14:03 David Chisnall <theraven@gna.org>
* libs/base/trunk/Headers/Foundation/NSBundle.h: Add __attribute__ * Headers/Foundation/NSBundle.h: Add __attribute__
((format_arg)) to [NSBundle -localizedStringForKey:value:table:]. ((format_arg)) to [NSBundle -localizedStringForKey:value:table:].
This informs the compiler that the output can be used anywhere This informs the compiler that the output can be used anywhere
that the first argument can be used, and should silence all of that the first argument can be used, and should silence all of

View file

@ -282,6 +282,13 @@
# endif # endif
#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. /* Include the appropriate header for ObjC2 blocks support if it is in use.
* *

View file

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

View file

@ -543,12 +543,5 @@ 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

@ -525,8 +525,10 @@ NSEnumerateMapTable(NSMapTable *table)
else else
{ {
NSMapEnumerator v = {0, 0, 0}; 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; v.bucket = (unsigned long)(uintptr_t)table;
return v; return v;
} }

View file

@ -36,7 +36,6 @@
#import "Foundation/NSLock.h" #import "Foundation/NSLock.h"
#import "Foundation/NSThread.h" #import "Foundation/NSThread.h"
#import "GNUstepBase/GSLock.h" #import "GNUstepBase/GSLock.h"
#import "GSPrivate.h"
static NSZone *_zone = 0; static NSZone *_zone = 0;
@ -791,16 +790,7 @@ 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__ GS_CONSUMED(name)
{
/* 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

@ -41,7 +41,6 @@
#import "Foundation/NSAutoreleasePool.h" #import "Foundation/NSAutoreleasePool.h"
#import "Foundation/NSData.h" #import "Foundation/NSData.h"
#import "Foundation/NSPort.h" #import "Foundation/NSPort.h"
#import "GSPrivate.h"
@class NSMutableDataMalloc; @class NSMutableDataMalloc;
@interface NSMutableDataMalloc : NSObject // Help the compiler @interface NSMutableDataMalloc : NSObject // Help the compiler
@ -617,17 +616,7 @@ static IMP _xRefImp; /* Serialize a crossref. */
obj = rep; obj = rep;
GSIArraySetItemAtIndex(_objAry, (GSIArrayItem)obj, xref); GSIArraySetItemAtIndex(_objAry, (GSIArrayItem)obj, xref);
} }
#ifdef __clang__ GS_CONSUMED(rep)
{
/* 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;
@ -735,16 +724,7 @@ static IMP _xRefImp; /* Serialize a crossref. */
*/ */
address = &dummy; address = &dummy;
(*_dTagImp)(_src, dTagSel, &info, &xref, &_cursor); (*_dTagImp)(_src, dTagSel, &info, &xref, &_cursor);
#ifdef __clang__ GS_CONSUMED(classInfo)
{
/* 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,16 +577,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
{ {
GSIArrayAddItem(&info->array, (GSIArrayItem)((id)s)); GSIArrayAddItem(&info->array, (GSIArrayItem)((id)s));
} }
#ifdef __clang__ GS_CONSUMED(s)
{
/* 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;
} }
@ -623,16 +614,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
{ {
GSIArrayAddItem(&info->array, (GSIArrayItem)((id)s)); GSIArrayAddItem(&info->array, (GSIArrayItem)((id)s));
} }
#ifdef __clang__ GS_CONSUMED(s)
{
/* 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;
} }

View file

@ -460,18 +460,7 @@ 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);
GS_CONSUMED(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;