Ensure d_img_out device memory is freed