libmemdisc: use local output buffers for malloc and free

We've noticed concurrency issues in discovery stage 1. We use
local output buffers in the functions malloc and free by now to
fix this. We only use half size buffers by now (2048) to reduce
additional static memory usage and as we hook two functions.

We also simplify the output format.
ugtrain: add discovery stage 1 post-processing