Analyzed code and fixed potential memory leaks