Crash with NSURL URLWithString

I am seeing crash reports with our users at this line of code

NSURL *url = [NSURL URLWithString:self->urlAddress];

self->urlAddress is never nil.

My understanding is that if self->urlAddress is malformed in someway then URLWithString should return nil but it seems to crash the thread as below.

Has anybody any suggestions as t what might be wrong?

Thread 3 name: Thread 3 Crashed: 0 CoreFoundation 0x00000001a73704a0 CFStringGetLength + 60 (CFInternal.h:889) 1 CoreFoundation 0x00000001a739b5b4 _CFURLCreateWithURLString + 84 (CFURL.c:2046) 2 Foundation 0x00000001a8635908 +[NSURL(NSURL) URLWithString:relativeToURL:] + 52 (NSURL.m:463) 3 Dubline 0x0000000102f3391c __58-[settingsAccountViewController reloadDublineSettingsPage]_block_invoke + 1024 (settingsAccountViewController.m:273) 4 CFNetwork 0x00000001a79f23dc __40-[__NSURLSessionLocal taskForClassInfo:]_block_invoke + 540 (LocalSession.mm:687) 5 CFNetwork 0x00000001a7a04768 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 244 (LocalSessionTask.mm:584) 6 libdispatch.dylib 0x00000001a6fb9a84 _dispatch_call_block_and_release + 32 (init.c:1466) 7 libdispatch.dylib 0x00000001a6fbb81c _dispatch_client_callout + 20 (object.m:559) 8 libdispatch.dylib 0x00000001a6fc3004 _dispatch_lane_serial_drain + 620 (inline_internal.h:2557) 9 libdispatch.dylib 0x00000001a6fc3c34 _dispatch_lane_invoke + 456 (queue.c:3862) 10 libdispatch.dylib 0x00000001a6fce4bc _dispatch_workloop_worker_thread + 764 (queue.c:6589) 11 libsystem_pthread.dylib 0x00000001f304a7a4 0x1f3047000 + 14244 12 libsystem_pthread.dylib 0x00000001f305174c 0x1f3047000 + 42828

could you show more code, and show the url (unless it is a local file URL)? Did you try to access the URL directly ?

Doc says:

This method expects URLString to contain only characters that are allowed in a properly formed URL. All other characters must be properly percent escaped. Any percent-escaped characters are interpreted using UTF-8 encoding.

Is it the case ?

I have eventually "trapped" the contents of the NSString that was converted to a NSURL which causes a crash in a real customer site

I show it below...( For our customer privacy I've hidden our server replacing it with xxxxxx.xxxxx.xx below but they are just lowercase alphabetical characters)

If I run this myself now then I don't get a crash!!! SO for some reason this just occurred in the real customer at that time!!

Anybody got any ideas?

I am running this on Thread 2 in case that is a factor?

NSString *dave = @"https://xxxxxxxx.xxxxx.xx/test/gate/b8e23d6e5dcfb0d5025fcc928f55ac1d5ae6ed03/settings";

NSURL *url = [NSURL URLWithString:dave]; <--- Crashes here

Just an update in case it helps anybody....

A function was called unexpectedly twice in quick succession leading to the NSSString being de-allocated before NSURL got to use it.

I put some defensive code in and it seems to have fixed it

Crash with NSURL URLWithString
 
 
Q