Memory leak fixes reported by Balazs Domjan.