Use cheaper static array.
Use simpler stack buffer.
Remove redundant free.
Use exit/fatal.