Fixed to flush pending buffers when closing

Signed-off-by: Tsuyoshi Ozawa <ozawa.tsuyoshi@gmail.com>
Merge pull request #34 from oza/fix-flush-pending-buffers-before-closing

Fixed to flush pending buffers before closing