Skip to content

Commit 4eea4c0

Browse files
authored
Address memory leaks in test suite (#903)
1 parent fb3fc2d commit 4eea4c0

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

test/test-mc-fle2-payload-iup-v2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ static void _test_mc_FLE2InsertUpdatePayloadV2_parses_crypto_params(_mongocrypt_
238238

239239
ASSERT(got.indexMax.value_type == BSON_TYPE_INT32);
240240
ASSERT_CMPINT32(got.indexMax.value.v_int32, ==, 1234567);
241+
242+
mc_FLE2InsertUpdatePayloadV2_cleanup(&got);
241243
}
242244

243245
void _mongocrypt_tester_install_fle2_payload_iup_v2(_mongocrypt_tester_t *tester) {

test/test-mc-range-mincover.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ typedef struct {
8585

8686
typedef struct _test_getMincover_args {
8787
mc_mincover_t *(*getMincover)(void *tests, size_t idx, mongocrypt_status_t *status);
88-
const char *(*expectError)(void *tests, size_t idx);
88+
const char *(*expectError)(void *tests, size_t idx, mongocrypt_status_t *status);
8989
const char *const *(*expectMincoverStrings)(void *tests, size_t idx);
9090
void (*dump)(void *tests, size_t idx, mc_mincover_t *got);
9191
} _test_getMincover_args;
@@ -171,23 +171,25 @@ static mc_mincover_t *_test_getMincoverDecimal128_helper(void *tests, size_t idx
171171
}
172172
#endif // MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
173173

174-
static const char *_test_expectError32(void *tests, size_t idx) {
174+
static const char *_test_expectError32(void *tests, size_t idx, mongocrypt_status_t *status) {
175175
BSON_ASSERT_PARAM(tests);
176+
BSON_ASSERT_PARAM(status);
176177
return ((Int32Test *)tests + idx)->expectError;
177178
}
178179

179-
static const char *_test_expectError64(void *tests, size_t idx) {
180+
static const char *_test_expectError64(void *tests, size_t idx, mongocrypt_status_t *status) {
180181
BSON_ASSERT_PARAM(tests);
182+
BSON_ASSERT_PARAM(status);
181183
return ((Int64Test *)tests + idx)->expectError;
182184
}
183185

184-
static const char *_test_expectErrorDouble(void *tests, size_t idx) {
186+
static const char *_test_expectErrorDouble(void *tests, size_t idx, mongocrypt_status_t *status) {
185187
BSON_ASSERT_PARAM(tests);
188+
BSON_ASSERT_PARAM(status);
186189
DoubleTest *test = ((DoubleTest *)tests + idx);
187190
if (test->min.set && test->max.set && test->precision.set) {
188191
// Expect an error for tests including an invalid min/max/precision.
189192
uint32_t ignored;
190-
mongocrypt_status_t *const status = mongocrypt_status_new();
191193
if (!mc_canUsePrecisionModeDouble(test->min.value, test->max.value, test->precision.value, &ignored, status)) {
192194
if (!mongocrypt_status_ok(status)) {
193195
return mongocrypt_status_message(status, NULL);
@@ -196,19 +198,18 @@ static const char *_test_expectErrorDouble(void *tests, size_t idx) {
196198
return "The domain of double values specified by the min, max, and precision cannot be represented in "
197199
"fewer than 64 bits";
198200
}
199-
mongocrypt_status_destroy(status);
200201
}
201202
return test->expectError;
202203
}
203204

204205
#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
205-
static const char *_test_expectErrorDecimal128(void *tests, size_t idx) {
206+
static const char *_test_expectErrorDecimal128(void *tests, size_t idx, mongocrypt_status_t *status) {
206207
BSON_ASSERT_PARAM(tests);
208+
BSON_ASSERT_PARAM(status);
207209
Decimal128Test *test = ((Decimal128Test *)tests + idx);
208210
if (test->min.set && test->max.set && test->precision.set) {
209211
// Expect an error for tests including an invalid min/max/precision.
210212
uint32_t ignored;
211-
mongocrypt_status_t *const status = mongocrypt_status_new();
212213
if (!mc_canUsePrecisionModeDecimal(test->min.value, test->max.value, test->precision.value, &ignored, status)) {
213214
if (!mongocrypt_status_ok(status)) {
214215
return mongocrypt_status_message(status, NULL);
@@ -374,7 +375,7 @@ static void _test_getMincover_impl(void *tests, size_t num_tests, _test_getMinco
374375
for (size_t i = 0; i < num_tests; i++) {
375376
mongocrypt_status_t *const status = mongocrypt_status_new();
376377
mc_mincover_t *got = args.getMincover(tests, i, status);
377-
const char *expectError = args.expectError(tests, i);
378+
const char *expectError = args.expectError(tests, i, status);
378379
if (expectError) {
379380
ASSERT_OR_PRINT_MSG(NULL == got, "expected error, got success");
380381
ASSERT_STATUS_CONTAINS(status, expectError);

test/test-mongocrypt-ctx-rewrap-many-datakey.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ static void _test_rewrap_many_datakey_need_kms_retry(_mongocrypt_tester_t *teste
571571
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
572572
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS); // To encrypt.
573573
mongocrypt_ctx_destroy(ctx);
574+
mongocrypt_destroy(crypt);
574575
}
575576

576577
static void _test_rewrap_many_datakey_need_kms_encrypt(_mongocrypt_tester_t *tester) {

0 commit comments

Comments
 (0)