add memory allocation protection