Fixed possible memory leaks.