Fixed to flush pending buffers when closing

Signed-off-by: Tsuyoshi Ozawa <ozawa.tsuyoshi@gmail.com>