Something wrong when using opencv with gstream to display video in hdmi because set_mode=1

The problem has been posted in When the hdmi not be connected, nvdrmvideosink double free happen.

But when I reboot the machine with no hdmi device connected , the progrom which has been changed to set_mode=0, goes to error again, this time, it shows “double free detected in tcache 2”.
If I reboot the machine with one hdmi device, it will ok, even if I unplug the hdmi device.