Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Fix to memory leak found during profiling application #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions SocketIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,8 @@ - (void) removeAcknowledgeForKey:(NSString *)key

- (void) onTimeout
{
if (_timeout) {
dispatch_source_cancel(_timeout);
_timeout = NULL;
}

[ self cleanupHeartbeatTimeout ];

DEBUGLOG(@"Timed out waiting for heartbeat.");
[self onDisconnect:[NSError errorWithDomain:SocketIOError
code:SocketIOHeartbeatTimeout
Expand All @@ -418,11 +415,8 @@ - (void) onTimeout
- (void) setTimeout
{
DEBUGLOG(@"start/reset timeout");
if (_timeout) {
dispatch_source_cancel(_timeout);
_timeout = NULL;
}

[ self cleanupHeartbeatTimeout ];

_timeout = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,
0,
0,
Expand Down Expand Up @@ -619,11 +613,8 @@ - (void) onDisconnect:(NSError *)error
[_queue removeAllObjects];

// Kill the heartbeat timer
if (_timeout) {
dispatch_source_cancel(_timeout);
_timeout = NULL;
}

[ self cleanupHeartbeatTimeout ];

// Disconnect the websocket, just in case
if (_transport != nil) {
// clear websocket's delegate - otherwise crashes
Expand Down Expand Up @@ -819,6 +810,15 @@ - (void) connection:(NSURLConnection *)connection
}
#endif

# pragma mark - Cleanup Heartbeat Timer
-(void) cleanupHeartbeatTimeout
{
if (_timeout) {
dispatch_source_cancel(_timeout);
dispatch_release(_timeout);
_timeout = NULL;
}
}

# pragma mark -

Expand All @@ -834,11 +834,8 @@ - (void) dealloc
_transport.delegate = nil;
_transport = nil;

if (_timeout) {
dispatch_source_cancel(_timeout);
_timeout = NULL;
}

[ self cleanupHeartbeatTimeout ];

_queue = nil;
_acks = nil;
}
Expand Down