mkd_cleanup() frees the output buffer.