Headless SegFault Memory Issue