Implemented safe alloc functions.