The conn might be released during the loop and then conn->bts is a null pointer and we end up crashing. Store the gsm_network in a local variable and access this one.