Fix an access to destroyed object error in ResourceLoader::cancel

Extend the reference count protection to enclose the ending
the event-action