Logic error for memory free.

Change the place will be better.
Recover and add free memory.