Flushing pending buffer before closing

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

Flushing pending buffer before closing