Skip to content

Commit

Permalink
more leak fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Mar 4, 2024
1 parent e881334 commit 88b73ac
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions Source/NSJSONSerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
static inline void
updateStringBuffer(ParserState* state)
{
NSRange r = {state->sourceIndex, BUFFER_SIZE};
NSUInteger end = [state->source length];
NSRange r = {state->sourceIndex, BUFFER_SIZE};
NSUInteger end = [state->source length];

if (end - state->sourceIndex < BUFFER_SIZE)
{
Expand Down Expand Up @@ -211,9 +211,10 @@
n = [stream read: &bytes[1] maxLength: i];
if (n == i)
{
str = [NSString stringWithUTF8String: (char*)bytes];
str = [[NSString alloc] initWithUTF8String: (char*)bytes];
[str getCharacters: state->buffer
range: NSMakeRange(0,1)];
[str release];
}
else
{
Expand Down Expand Up @@ -276,8 +277,8 @@
// Just use the string buffer fetch function to actually get the data
state->source = str;
updateStringBuffer(state);
state->source = stream;
RELEASE(str);
state->source = stream;
}

/**
Expand Down Expand Up @@ -340,7 +341,7 @@
state->error = [NSError errorWithDomain: NSCocoaErrorDomain
code: 0
userInfo: userInfo];
[userInfo release];
RELEASE(userInfo);
}


Expand Down Expand Up @@ -480,10 +481,10 @@
{
if (NO == [val makeImmutable])
{
NSString *str = [val copy];
NSMutableString *m = val;

RELEASE(val);
return str;
val = [m copy];
RELEASE(m);
}
}
return val;
Expand Down Expand Up @@ -1074,14 +1075,13 @@ + (NSData*) dataWithJSONObject: (id)obj
{
if (NULL != error)
{
NSDictionary *userInfo;

userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:
_(@"JSON writing error"), NSLocalizedDescriptionKey,
nil];
*error = [NSError errorWithDomain: NSCocoaErrorDomain
code: 0
userInfo: userInfo];
RELEASE(userInfo);
}
}
[str release];
Expand Down Expand Up @@ -1140,6 +1140,7 @@ + (id) JSONObjectWithStream: (NSInputStream *)stream
encoding: p.enc
freeWhenDone: NO];
updateStringBuffer(&p);
RELEASE(p.source);
/* Negative source index because we are before the
* current point in the buffer
*/
Expand All @@ -1150,12 +1151,11 @@ + (id) JSONObjectWithStream: (NSInputStream *)stream
obj = parseValue(&p);
// Consume any data in the stream that we've failed to read
updateStreamBuffer(&p);
RELEASE(p.source);
if (NULL != error)
{
*error = p.error;
}
return AUTORELEASE(obj);
return [obj autorelease];
}

+ (NSInteger) writeJSONObject: (id)obj
Expand Down

0 comments on commit 88b73ac

Please sign in to comment.