added safe wrapper for malloc