Removed bug wrong mem allocation size.
Removed use after free bug.