Fixed a possible access violation due to the added manual memory management.