Fixed possible crash on memory reallocation