Fix/memory leak 2

This PR fixes the memory leak issue on linux.