Add explicit calls to free buffer, in other to fix Clang Static Analyser warning about potential memory leak.