log: fix a memory leak when using log handler