Callers seem to try to handle the result NULL as denoting memory allocation failure. Allocation failure is fatal and the allocator will never return. The code could be simplified (and at least one goto eliminated).