Handle OOM issues

Resolved not checking realloc return value reported by cppcheck.
If OOM happens, crash as soon as possible.