Add explicit calls to free buffer, in other to fix Clang Static Analyser warning about potential memory leak.
Remove one level of indentation for clarity.