Skip to content

Commit

Permalink
Fixing crash from over-release of RKParams.
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewatters committed Jun 30, 2011
1 parent a78b4c6 commit 72f2669
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Code/CoreData/RKManagedObjectLoader.m
Expand Up @@ -92,6 +92,11 @@ - (BOOL)prepareURLRequest {
}

- (void)deleteCachedObjectsMissingFromResult:(RKObjectMappingResult*)result {
if (! [self isGET]) {
RKLogDebug(@"Skipping cleanup of objects via managed object cache: only used for GET requests.");
return;
}

if ([self.URL isKindOfClass:[RKURL class]]) {
RKURL* rkURL = (RKURL*)self.URL;

Expand Down
17 changes: 10 additions & 7 deletions Code/Network/RKParams.m
Expand Up @@ -192,13 +192,16 @@ - (void)open {
}

- (void)close {
_streamStatus = NSStreamStatusClosed;
RKLogTrace(@"RKParams stream closed. Releasing self.");

// NOTE: When we are assigned to the URL request, we get
// retained. We release ourselves here to ensure the retain
// count will hit zero after upload is complete.
[self release];
if (_streamStatus != NSStreamStatusClosed) {
_streamStatus = NSStreamStatusClosed;

RKLogTrace(@"RKParams stream closed. Releasing self.");

// NOTE: When we are assigned to the URL request, we get
// retained. We release ourselves here to ensure the retain
// count will hit zero after upload is complete.
[self release];
}
}

- (NSStreamStatus)streamStatus {
Expand Down
4 changes: 4 additions & 0 deletions RestKit.xcodeproj/project.pbxproj
Expand Up @@ -101,6 +101,7 @@
25432041125618F000A315CF /* RKParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 25432040125618F000A315CF /* RKParser.h */; settings = {ATTRIBUTES = (Public, ); }; };
25432064125632A300A315CF /* RKJSONParserYAJL.m in Sources */ = {isa = PBXBuildFile; fileRef = 253A08B71255212300976E89 /* RKJSONParserYAJL.m */; };
25432065125632AA00A315CF /* RKJSONParserSBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 253A08B61255212300976E89 /* RKJSONParserSBJSON.m */; };
2559209713BD1B8700E9C29C /* RKParamsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 2559208213BD1A4000E9C29C /* RKParamsSpec.m */; };
255DE05E10FFA05800A85891 /* RKHuman.m in Sources */ = {isa = PBXBuildFile; fileRef = 255DE05D10FFA05800A85891 /* RKHuman.m */; };
255DE0E210FFABA500A85891 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 255DE0E110FFABA500A85891 /* CoreData.framework */; };
255DE0F410FFAC0A00A85891 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 255DE0F310FFAC0A00A85891 /* SystemConfiguration.framework */; };
Expand Down Expand Up @@ -479,6 +480,7 @@
253E04C413798D72005D2E15 /* RKErrorMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKErrorMessage.m; sourceTree = "<group>"; };
25431EBA1255640800A315CF /* CoreData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreData.h; sourceTree = "<group>"; };
25432040125618F000A315CF /* RKParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKParser.h; sourceTree = "<group>"; };
2559208213BD1A4000E9C29C /* RKParamsSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RKParamsSpec.m; sourceTree = "<group>"; };
255DE05C10FFA05800A85891 /* RKHuman.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKHuman.h; sourceTree = "<group>"; };
255DE05D10FFA05800A85891 /* RKHuman.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKHuman.m; sourceTree = "<group>"; };
255DE0E110FFABA500A85891 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -1346,6 +1348,7 @@
259D56B4132E706D00897272 /* RKAuthenticationSpec.m */,
250C296B13411E60000A3551 /* RKRequestQueueSpec.m */,
25ACF1AC13BB9D480067B380 /* RKURLSpec.m */,
2559208213BD1A4000E9C29C /* RKParamsSpec.m */,
);
path = Network;
sourceTree = "<group>";
Expand Down Expand Up @@ -2116,6 +2119,7 @@
25AA85D613B1065000A95E2A /* RKObjectLoaderSpec.m in Sources */,
2515E7BD13B36AC100E013A4 /* RKObjectLoaderSpecResultModel.m in Sources */,
25ACF1AD13BB9D490067B380 /* RKURLSpec.m in Sources */,
2559209713BD1B8700E9C29C /* RKParamsSpec.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 4 additions & 4 deletions RestKit.xcodeproj/xcshareddata/xcschemes/UISpec.xcscheme
Expand Up @@ -78,22 +78,22 @@
<EnvironmentVariable
key = "UISPEC_EXIT_ON_FINISH"
value = "NO"
isEnabled = "NO">
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "NSZombieEnabled"
value = "YES"
isEnabled = "NO">
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "UISPEC_SPEC"
value = "RKObjectSerializerSpec"
value = "RKParamsSpec"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "UISPEC_EXAMPLE"
value = "itShouldSetAnErrorAndReturnNilIfItCantSerialize"
isEnabled = "YES">
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "NSAutoreleaseHaltOnNoPool"
Expand Down
34 changes: 34 additions & 0 deletions Specs/Network/RKParamsSpec.m
@@ -0,0 +1,34 @@
//
// RKParamsSpec.m
// RestKit
//
// Created by Blake Watters on 6/30/11.
// Copyright 2011 Two Toasters. All rights reserved.
//

#import "RKSpecEnvironment.h"
#import "RKParams.h"
#import "RKRequest.h"

@interface RKParamsSpec : RKSpec

@end

@implementation RKParamsSpec

- (void)itShouldNotOverReleaseTheParams {
RKLogConfigureByName("RestKit/Network*", RKLogLevelTrace);
NSDictionary* dictionary = [NSDictionary dictionaryWithObject:@"foo" forKey:@"bar"];
RKParams* params = [[RKParams alloc] initWithDictionary:dictionary];
NSURL* URL = [NSURL URLWithString:[RKSpecGetBaseURL() stringByAppendingFormat:@"/echo_params"]];
RKSpecResponseLoader* responseLoader = [RKSpecResponseLoader responseLoader];
RKRequest* request = [[RKRequest alloc] initWithURL:URL];
request.method = RKRequestMethodPOST;
request.params = params;
request.delegate = responseLoader;
[request sendAsynchronously];
[responseLoader waitForResponse];
[request release];
}

@end

0 comments on commit 72f2669

Please sign in to comment.