Fix memory leaks

Related to rhbz#803774.

Signed-off-by: Martin Milata <mmilata@redhat.com>