From: Aki Tuomi Date: Fri, 15 Jul 2016 13:30:51 +0000 (+0300) Subject: dcrypt-iostream: Ref/unref keys X-Git-Tag: 2.3.0.rc1~3259 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55a7fe1e4637a8dbc6184b54edeb74ac8276b2c1;p=thirdparty%2Fdovecot%2Fcore.git dcrypt-iostream: Ref/unref keys --- diff --git a/src/lib-dcrypt/istream-decrypt.c b/src/lib-dcrypt/istream-decrypt.c index cbe9b3e967..6df03b5557 100644 --- a/src/lib-dcrypt/istream-decrypt.c +++ b/src/lib-dcrypt/istream-decrypt.c @@ -132,6 +132,7 @@ ssize_t i_stream_decrypt_read_header_v1(struct decrypt_istream *stream, 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 @@ ssize_t i_stream_decrypt_key(struct decrypt_istream *stream, const char *malg, u return -1; } if (ret > 0) { + dcrypt_key_ref_private(stream->priv_key); have_key = TRUE; break; } @@ -803,6 +805,8 @@ void i_stream_decrypt_destroy(struct iostream_private *stream) 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 @@ i_stream_create_decrypt(struct istream *input, struct dcrypt_private_key *priv_k 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; } diff --git a/src/lib-dcrypt/ostream-encrypt.c b/src/lib-dcrypt/ostream-encrypt.c index aca819eb93..37a937673d 100644 --- a/src/lib-dcrypt/ostream-encrypt.c +++ b/src/lib-dcrypt/ostream-encrypt.c @@ -561,7 +561,7 @@ void o_stream_encrypt_destroy(struct iostream_private *stream) 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 @@ o_stream_create_encrypt(struct ostream *output, const char *algorithm, struct encrypt_ostream *estream = o_stream_create_encrypt_common(flags); int ec; + dcrypt_key_ref_public(box_pub); estream->pub = box_pub; T_BEGIN {