Use free(mem) to avoid memLeak cppcheck error

The error happens with
<pre>
mem = 0;
</pre>