Fixed potential memory leak in shared_ptr misuse