How to solve C/C++ memory leaking (in Linux)?