aboutsummaryrefslogtreecommitdiff
path: root/Foundation
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-10-29 12:05:03 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-10-29 12:05:03 +0000
commite1cbd4dc301f0f7e0a0fd7616a958bfaeb615b67 (patch)
tree88ac9898986612d4fbab6ba67079ae6337d84267 /Foundation
parent24322f87faace9ffabe0787dbfb27eeeea9aed31 (diff)
[Author: iwade]
Fix some garbage collecion related leaks. Discovered in a run of the Clang Static Analyzer: http://clang-analyzer.llvm.org/ R=dmaclach APPROVED=dmaclach DELTA=17 (11 added, 0 deleted, 6 changed)
Diffstat (limited to 'Foundation')
-rw-r--r--Foundation/GTMNSDictionary+CaseInsensitive.m21
1 files changed, 16 insertions, 5 deletions
diff --git a/Foundation/GTMNSDictionary+CaseInsensitive.m b/Foundation/GTMNSDictionary+CaseInsensitive.m
index 96494c2..a207000 100644
--- a/Foundation/GTMNSDictionary+CaseInsensitive.m
+++ b/Foundation/GTMNSDictionary+CaseInsensitive.m
@@ -18,6 +18,7 @@
#import "GTMNSDictionary+CaseInsensitive.h"
#import "GTMDefines.h"
+#import "GTMGarbageCollection.h"
#import <CoreFoundation/CoreFoundation.h>
@interface NSMutableDictionary (GTMNSMutableDictionaryCaseInsensitiveAdditions)
@@ -84,9 +85,14 @@ static CFHashCode CaseInsensitiveHashCallback(const void *value) {
keyCallbacks.equal = CaseInsensitiveEqualCallback;
keyCallbacks.hash = CaseInsensitiveHashCallback;
- self = (id)CFDictionaryCreate(kCFAllocatorDefault,
- keys, values, count, &keyCallbacks,
- &kCFTypeDictionaryValueCallBacks);
+ // GTMNSMakeCollectable drops the retain count in GC mode so the object can
+ // be garbage collected.
+ // GTMNSMakeCollectable not GTMCFAutorelease because this is an initializer
+ // and in non-GC mode we need to return a +1 retain count object.
+ self = GTMNSMakeCollectable(
+ CFDictionaryCreate(kCFAllocatorDefault,
+ keys, values, count, &keyCallbacks,
+ &kCFTypeDictionaryValueCallBacks));
free(keys);
free(values);
@@ -105,8 +111,13 @@ static CFHashCode CaseInsensitiveHashCallback(const void *value) {
- (id)gtm_initWithDictionaryCaseInsensitive:(NSDictionary *)dictionary {
if ((self = [super gtm_initWithDictionaryCaseInsensitive:dictionary])) {
- id copy = (id)CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0,
- (CFDictionaryRef)self);
+ // GTMNSMakeCollectable drops the retain count in GC mode so the object can
+ // be garbage collected.
+ // GTMNSMakeCollectable not GTMCFAutorelease because this is an initializer
+ // and in non-GC mode we need to return a +1 retain count object.
+ id copy = GTMNSMakeCollectable(
+ CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0,
+ (CFDictionaryRef)self));
[self release];
self = copy;
}