Which standard? In C/C++ or Lua?
May be some C implementations may fail, but these are certainly bad, excemt for saying that the block was not real located but is the original block still usable? I think it is even if the realloc returned a null. If this is not the case, then don't use the realloc from C, but only malloc, perform the memcpy after if it succeeds, and free the old block. That's what all decent C library should do. But then you need your own memory manager. Just a waste of time, consider changing your c library for another that will correctly handle block size reduction without ever failing if the original block pointer was valid