]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail-crypt: Fix memory leak in "doveadm mailbox cryptokey generate"
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 12 Jun 2018 13:56:51 +0000 (16:56 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 22 Aug 2018 09:44:17 +0000 (12:44 +0300)
src/plugins/mail-crypt/doveadm-mail-crypt.c

index 612f469ba9b2f7f079f9f8b420cc56f3111ba7d7..e7a83d8bc70333346832e18b07d18f29630617c8 100644 (file)
@@ -342,6 +342,7 @@ static int mcp_keypair_generate_run(struct doveadm_mail_cmd_context *_ctx,
                                                key_id, &error)) {
                                i_error("dcrypt_key_id_public() failed: %s",
                                        error);
+                               dcrypt_key_unref_public(&user_key);
                                return -1;
                        }
                        const char *hash = binary_to_hex(key_id->data,
@@ -351,6 +352,7 @@ static int mcp_keypair_generate_run(struct doveadm_mail_cmd_context *_ctx,
                        res->id = p_strdup(_ctx->pool, hash);
                        res->success = TRUE;
                        ctx->matched_keys++;
+                       dcrypt_key_unref_public(&user_key);
                        return 1;
                }
                struct dcrypt_keypair pair;
@@ -371,8 +373,10 @@ static int mcp_keypair_generate_run(struct doveadm_mail_cmd_context *_ctx,
                ctx->matched_keys++;
        }
 
-       if (ctx->userkey_only)
+       if (ctx->userkey_only) {
+               dcrypt_key_unref_public(&user_key);
                return 0;
+       }
 
        const char *const *patterns = (const char *const[]){ "*", NULL };