Fix memory leak and compilation error when NDEBUG is undefined