[trunk] WIP: correct some memory leaks in applications functions