Fix memory leak

I revised the memory leak that I discovered using valgrind.
Please merge, if there is no problem in correction.