Fix double free in case of an error

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>