catches malloc error and raises a RuntimeError