Fix leaks and null dereferences in net_crypto

It makes the clang static analyzer happy.