From 0caa1d3249d85050d0e3422d602e630aca574e0b Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Tue, 14 Mar 2023 16:25:27 -0400 Subject: [PATCH] MONGOCRYPT-554 fix cleanup in `_fle2_finalize` error case (#595) * add missing destroy and context fail on error * remove unnecessary `bson_init` `bson_copy_to` initializes the destination --- src/mongocrypt-ctx-encrypt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mongocrypt-ctx-encrypt.c b/src/mongocrypt-ctx-encrypt.c index 63612d43b..fe166f0dc 100644 --- a/src/mongocrypt-ctx-encrypt.c +++ b/src/mongocrypt-ctx-encrypt.c @@ -1602,7 +1602,6 @@ _fle2_finalize (mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out) /* If marked_cmd buffer is empty, there are no markings to encrypt. */ if (_mongocrypt_buffer_empty (&ectx->marked_cmd)) { /* Append 'encryptionInformation' to the original command. */ - bson_init (&converted); bson_copy_to (&original_cmd_bson, &converted); } else { bson_t as_bson; @@ -1649,7 +1648,9 @@ _fle2_finalize (mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out) moe_result result = must_omit_encryptionInformation (command_name, &converted, ctx->status); if (!result.ok) { - return false; + bson_destroy (&converted); + bson_destroy (deleteTokens); + return _mongocrypt_ctx_fail (ctx); } /* Append a new 'encryptionInformation'. */