Fixes for "Conditional jump or move depends on uninitialised value(s)"
and memleaks reported by valgrind.

Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>