Fix memory leak & optimize default compiler flags