Working malloc except edgecase bug