Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit 0a233ae

Browse files
committed
CouchQuery error property: fixed memory leak and other issues
1 parent 711b1c9 commit 0a233ae

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Couch/CouchQuery.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ typedef enum {
8585

8686
@property BOOL sequences;
8787

88-
/** If non-nil, the error of the last execution of the query
89-
If nil, the last exexution of the query was successful */
90-
@property (readonly) NSError* error;
88+
/** If non-nil, the error of the last execution of the query.
89+
If nil, the last exexution of the query was successful */
90+
@property (readonly,retain) NSError* error;
9191

9292
/** Starts an asynchronous query of the CouchDB view.
9393
When complete, the operation's resultObject will be the CouchQueryEnumerator. */

Couch/CouchQuery.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ - (id) initWithDatabase: (CouchDatabase*)db result: (id)result;
3232
@end
3333

3434

35+
@interface CouchQuery ()
36+
@property (readwrite,retain) NSError *error;
37+
@end
38+
3539

3640
@implementation CouchQuery
3741

@@ -143,12 +147,11 @@ - (CouchQueryEnumerator*) rowsIfChanged {
143147

144148

145149
- (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)error {
146-
error = [super operation: op willCompleteWithError: error];
147-
if (error) {
148-
Warn(@"%@ failed with %@", self, error);
149-
_error = [error retain];
150-
}
151-
if (!error && op.httpStatus == 200) {
150+
self.error = [super operation: op willCompleteWithError: error];
151+
if (_error)
152+
Warn(@"%@ failed with %@", self, _error);
153+
154+
if (!_error && op.httpStatus == 200) {
152155
NSDictionary* result = $castIf(NSDictionary, op.responseBody.fromJSON);
153156
NSArray* rows = $castIf(NSArray, [result objectForKey: @"rows"]);
154157
if (rows) {
@@ -157,13 +160,12 @@ - (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)erro
157160
result: result] autorelease];
158161
} else {
159162
Warn(@"Couldn't parse rows from CouchDB view response");
160-
error = [RESTOperation errorWithHTTPStatus: 502
163+
self.error = [RESTOperation errorWithHTTPStatus: 502
161164
message: @"Couldn't parse rows from CouchDB view response"
162165
URL: self.URL];
163-
_error = [error retain];
164166
}
165167
}
166-
return error;
168+
return _error;
167169
}
168170

169171

0 commit comments

Comments
 (0)