fix memory leak

Please see my gist for details https://gist.github.com/sonots/7982855

I also pull requested to fluentd itself to fix this problem from the side of fluentd https://github.com/fluent/fluentd/pull/230, but could you merge this for fluentd users of lower versions?