How to properly handle NVDEC_THROW_ERROR when NvDecoder crapped out?

Hi, I am building an application using NvDecoder class from https://github.com/NVIDIA/video-sdk-samples/tree/master/Samples/NvCodec to decode H265 stream.

I am using SDK 10.1 on Windows. RTX1050 with driver version 461.09

Everything works great until I need to properly handle NVDEC_THROW_ERROR and close the application gracefully.
In my specific case, I accidentally provided the wrong dimension of the bitstream, and NvDecoder throws an error in NvDecoder::ReconfigureDecoder
https://github.com/NVIDIA/video-sdk-samples/blob/aa3544dcea2fe63122e4feb83bf805ea40e58dbe/Samples/NvCodec/NvDecoder/NvDecoder.cpp#L293

My C++ program caught the exception and starts to clean things up. However, no matter how I tried, the program constantly segfault or deadlock in this step of NvDecoder destructor https://github.com/NVIDIA/video-sdk-samples/blob/aa3544dcea2fe63122e4feb83bf805ea40e58dbe/Samples/NvCodec/NvDecoder/NvDecoder.cpp#L551

I’ve also tried feeding an EoS flag to the decoder, like so: DecodeLockFrame(nullptr, 0, &pp_decoded_frame, &num_frame_returned, CUVID_PKT_ENDOFSTREAM); But that also led to a deadlock.

Am I missing something from the documentation? How can I destroy the NvDecoder object properly at this stage?