Fixed a potential overflow issue with realloc() that Sebastian Krahmer