Fixed potential NULL dereference