fix template buffer memory error