Add error handling for memory allocation failure.
Fix guard macros.