Skip to content

Uncaught exception when calling didCloseWithCode with null obj #10

Description

@angeloh

The variable 'reason' might be null and would cause exception.

- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean {
  NSLog(@"WebSocket closed");
  [_handler onCloseWithComGoodowRealtimeJsonJsonObject:@{@"code":[NSNumber numberWithInteger:code], @"reason":reason, @"wasClean":[NSNumber numberWithBool:wasClean]}];

  _handler = nil;
  if (_webSocket.delegate) _webSocket.delegate = nil;
  _webSocket = nil;
}

If null, an exception shows up like this:

2014-08-21 12:01:54.009 [602:60b] Crash! Uncaught exception, *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]
2014-08-21 12:01:54.640 [602:60b] Crash! Stack trace: (
    0   CoreFoundation                      0x307dbf9b <redacted> + 154
    1   libobjc.A.dylib                     0x3af8cccf objc_exception_throw + 38
    2   CoreFoundation                      0x3071a413 <redacted> + 530
    3   CoreFoundation                      0x3071a1db <redacted> + 50
    4   MyApp                             0x005af6c9 -[ComGoodowRealtimeObjcObjCWebSocket webSocket:didCloseWithCode:reason:wasClean:] + 384
    5   MyApp                            0x006c361b __27-[SRWebSocket _pumpWriting]_block_invoke + 282
    6   libdispatch.dylib                   0x3b474833 <redacted> + 10
    7   libdispatch.dylib                   0x3b47481f <redacted> + 22
    8   libdispatch.dylib                   0x3b474777 <redacted> + 254
    9   CoreFoundation                      0x307a68a1 <redacted> + 8
    10  CoreFoundation                      0x307a5175 <redacted> + 1300
    11  CoreFoundation                      0x3070febf CFRunLoopRunSpecific + 522
    12  CoreFoundation                      0x3070fca3 CFRunLoopRunInMode + 106
    13  GraphicsServices                    0x35615663 GSEventRunModal + 138
    14  UIKit                               0x3305c14d UIApplicationMain + 1136
    15  MyApp                               0x000260e5 main + 140
    16  libdyld.dylib                       0x3b499ab7 <redacted> + 2
)
2014-08-21 12:01:54.646 Peer.im[602:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions