Skip to content

Commit 0caa1d3

Browse files
committed
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
1 parent b450387 commit 0caa1d3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/mongocrypt-ctx-encrypt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,6 @@ _fle2_finalize (mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out)
16021602
/* If marked_cmd buffer is empty, there are no markings to encrypt. */
16031603
if (_mongocrypt_buffer_empty (&ectx->marked_cmd)) {
16041604
/* Append 'encryptionInformation' to the original command. */
1605-
bson_init (&converted);
16061605
bson_copy_to (&original_cmd_bson, &converted);
16071606
} else {
16081607
bson_t as_bson;
@@ -1649,7 +1648,9 @@ _fle2_finalize (mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out)
16491648
moe_result result =
16501649
must_omit_encryptionInformation (command_name, &converted, ctx->status);
16511650
if (!result.ok) {
1652-
return false;
1651+
bson_destroy (&converted);
1652+
bson_destroy (deleteTokens);
1653+
return _mongocrypt_ctx_fail (ctx);
16531654
}
16541655

16551656
/* Append a new 'encryptionInformation'. */

0 commit comments

Comments
 (0)