Fixed potential memleaks