Fix double definition of private method and add handling for unlikely malloc failure