Fix some memory leaks

Signed-off-by: Nikolay Nizov <nizovn@gmail.com>