fix memory leaks

Signed-off-by: Sami Kerola <kerolasa@iki.fi>