Patch for bug144: Crash because entity was freed while waiting for the mutex. Add NULL check for the entity after acquiring the mutex.