Fixed invalid memory access when shared_ptr has expired