Handle errors from realloc

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>