Fixed some leaks and an unitialized heap region, trying to fix the error in handle_sys_write