changeset 20565:b550a486b502

dcrypt-iostream: Ref/unref keys
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Fri, 15 Jul 2016 16:30:51 +0300
parents dced7deca4d6
children 6ebb03fc9a25
files src/lib-dcrypt/istream-decrypt.c src/lib-dcrypt/ostream-encrypt.c
diffstat 2 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-dcrypt/istream-decrypt.c	Fri Jul 15 16:27:03 2016 +0300
+++ b/src/lib-dcrypt/istream-decrypt.c	Fri Jul 15 16:30:51 2016 +0300
@@ -132,6 +132,7 @@
 				io_stream_set_error(&stream->istream.iostream, "Private key not available");
 				return -1;
 			}
+			dcrypt_key_ref_private(stream->priv_key);
 		} else {
 			io_stream_set_error(&stream->istream.iostream, "Private key not available");
 			return -1;
@@ -306,6 +307,7 @@
 				return -1;
 			}
 			if (ret > 0) {
+				dcrypt_key_ref_private(stream->priv_key);
 				have_key = TRUE;
 				break;
 			}
@@ -803,6 +805,8 @@
 		dcrypt_ctx_sym_destroy(&(dstream->ctx_sym));
 	if (dstream->ctx_mac != NULL)
 		dcrypt_ctx_hmac_destroy(&(dstream->ctx_mac));
+	if (dstream->priv_key != NULL)
+		dcrypt_key_unref_private(&(dstream->priv_key));
 
 	i_stream_unref(&(dstream->istream.parent));
 }
@@ -835,6 +839,7 @@
 	struct decrypt_istream *dstream;
 
 	dstream = i_stream_create_decrypt_common(input);
+	dcrypt_key_ref_private(priv_key);
 	dstream->priv_key = priv_key;
 	return &dstream->istream.istream;
 }
--- a/src/lib-dcrypt/ostream-encrypt.c	Fri Jul 15 16:27:03 2016 +0300
+++ b/src/lib-dcrypt/ostream-encrypt.c	Fri Jul 15 16:30:51 2016 +0300
@@ -561,7 +561,7 @@
 	if (estream->key_data != NULL) i_free(estream->key_data);
 	if (estream->cipher_oid != NULL) buffer_free(&(estream->cipher_oid));
 	if (estream->mac_oid != NULL) buffer_free(&(estream->mac_oid));
-
+	if (estream->pub != NULL) dcrypt_key_unref_public(&(estream->pub));
 	o_stream_unref(&estream->ostream.parent);
 }
 
@@ -645,6 +645,7 @@
 	struct encrypt_ostream *estream = o_stream_create_encrypt_common(flags);
 	int ec;
 
+	dcrypt_key_ref_public(box_pub);
 	estream->pub = box_pub;
 
 	T_BEGIN {