Add additional check for malloc