Merged memory leak fix from devel