Better error handling in cert generation

Now it should correctly free all resources in case
of failure.
Merge pull request #60 from vhbit/cert-gen-cleanup

Better error handling in cert generation