Fix valgrind warnings

Signed-off-by: Rafał Malinowski <rafal.malinowski@corp.bluecherry.net>
Merge pull request #183 from vogel/valgrind-fixes

Fix valgrind warnings