Crash on-device in gotMemoryWarning() in ofxiPhoneAlerts.h

I’ve seen this sort of crash in iOS device logs a couple of times, which I can’t reproduce in the simulator:

  
Exception Type:  EXC_BAD_ACCESS (SIGBUS)  
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000  
Crashed Thread:  0  
  
Thread 0 name:  Dispatch queue: com.apple.main-thread  
Thread 0 Crashed:  
0   LandOfLegends                 	0x0025119e ofxiPhoneAlertsHandler::gotMemoryWarning() (ofxiPhoneAlerts.h:69)  
1   LandOfLegends                 	0x00250c22 -[ofxiPhoneAppDelegate applicationDidReceiveMemoryWarning:] (ofxiPhoneAppDelegate.mm:276)  
  

gotMemoryWarning() in ofxiPhoneAlerts.h looks like:

  
	//alerts engine will call this when the program receives a memory warning   
	void gotMemoryWarning()  
	{  
		for(std::list<ofxiPhoneAlertsListener*>::iterator it=listeners.begin(); it!=listeners.end(); ++it) {  
			ofxiPhoneAlertsListener* o = *it;  
			o->gotMemoryWarning();  
		}  
	}  
  

Line 69 is o->gotMemoryWarning(), so this smells like o is NULL. So I’m changing it to:

  
	//alerts engine will call this when the program receives a memory warning   
	void gotMemoryWarning()  
	{  
		for(std::list<ofxiPhoneAlertsListener*>::iterator it=listeners.begin(); it!=listeners.end(); ++it) {  
			ofxiPhoneAlertsListener* o = *it;  
			if (o != NULL) {  
				o->gotMemoryWarning();  
			}  
		}  
	}  
  

This might be moot because the app could be getting torn down, but maybe it’ll change the flavor of future crash logs.