[trunk] fix possible memory leak on realloc failure