Skip to content

Commit 4bd5c14

Browse files
committed
leaks in tests
1 parent 95dc35b commit 4bd5c14

File tree

7 files changed

+40
-8
lines changed

7 files changed

+40
-8
lines changed

tests/mock_server/mock-rs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ mock_rs_with_autoismaster (int32_t max_wire_version,
134134
rs->n_secondaries = n_secondaries;
135135
rs->n_arbiters = n_arbiters;
136136
rs->request_timeout_msec = 10 * 1000;
137-
_mongoc_array_init (&rs->secondaries, sizeof (mock_server_t *));
138-
_mongoc_array_init (&rs->arbiters, sizeof (mock_server_t *));
139-
_mongoc_array_init (&rs->servers, sizeof (mock_server_t *));
140137
rs->q = q_new ();
141138
rs->verbose = test_framework_getenv_bool ("MONGOC_TEST_SERVER_VERBOSE");
142139

@@ -263,6 +260,7 @@ mock_rs_run (mock_rs_t *rs)
263260
}
264261

265262
/* add all servers to replica set */
263+
_mongoc_array_init (&rs->servers, sizeof(mock_server_t *));
266264
if (rs->has_primary) {
267265
_mongoc_array_append_val (&rs->servers, rs->primary);
268266
}
@@ -504,6 +502,8 @@ mock_rs_receives_command (mock_rs_t *rs,
504502
return NULL;
505503
}
506504

505+
bson_free (ns);
506+
507507
return request;
508508
}
509509

tests/test-bulk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,7 @@ test_large_inserts_ordered (void)
21372137

21382138
bson_destroy (&reply);
21392139
mongoc_bulk_operation_destroy (bulk);
2140+
mongoc_cursor_destroy (cursor);
21402141
mongoc_collection_destroy (collection);
21412142
bson_destroy (huge_doc);
21422143
mongoc_client_destroy (client);

tests/test-mongoc-client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,8 @@ test_mongoc_client_unix_domain_socket (void *context)
953953
assert (bson_iter_init_find (&iter, &reply, "ok"));
954954

955955
bson_destroy (&reply);
956-
957956
mongoc_client_destroy (client);
957+
bson_free (uri_str);
958958
}
959959

960960

tests/test-mongoc-collection-find.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ _test_collection_find_live (test_collection_find_t *test_data)
141141
bson_free (drop_cmd);
142142
mongoc_cursor_destroy (cursor);
143143
mongoc_collection_destroy (collection);
144+
mongoc_database_destroy (database);
144145
bson_free (collection_name);
145146
mongoc_client_destroy (client);
146147
}
@@ -236,6 +237,8 @@ _test_collection_op_query_or_find_command (
236237
test_data->filename, test_data->lineno,
237238
test_data->funcname, test_data->expected_result));
238239

240+
request_destroy (request);
241+
future_destroy (future);
239242
mongoc_cursor_destroy (cursor);
240243
mongoc_collection_destroy (collection);
241244
mongoc_client_destroy (client);
@@ -282,6 +285,8 @@ _reply_to_op_query (request_t *request,
282285

283286
mock_server_reply_multi (request, MONGOC_REPLY_NONE, docs,
284287
test_data->n_results, 0 /* cursor_id */);
288+
289+
bson_free (docs);
285290
}
286291

287292

@@ -1049,6 +1054,7 @@ _test_tailable_timeout (bool pooled)
10491054
bson_destroy (&reply);
10501055
mongoc_cursor_destroy (cursor);
10511056
mongoc_collection_destroy (collection);
1057+
mongoc_database_destroy (database);
10521058
bson_free (collection_name);
10531059

10541060
if (pooled) {

tests/test-mongoc-collection.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,8 @@ test_count_read_concern (void)
13291329
mock_server_replies_simple (request, "{ 'n' : 42, 'ok' : 1 } ");
13301330
count = future_get_int64_t (future);
13311331
ASSERT_OR_PRINT (count == 42, error);
1332+
request_destroy (request);
1333+
future_destroy (future);
13321334

13331335
/* readConcern: { level: majority } */
13341336
rc = mongoc_read_concern_new ();
@@ -1347,7 +1349,8 @@ test_count_read_concern (void)
13471349
count = future_get_int64_t (future);
13481350
ASSERT_OR_PRINT (count == 43, error);
13491351
mongoc_read_concern_destroy (rc);
1350-
1352+
request_destroy (request);
1353+
future_destroy (future);
13511354

13521355
/* readConcern: { level: local } */
13531356
rc = mongoc_read_concern_new ();
@@ -1366,6 +1369,8 @@ test_count_read_concern (void)
13661369
count = future_get_int64_t (future);
13671370
ASSERT_OR_PRINT (count == 44, error);
13681371
mongoc_read_concern_destroy (rc);
1372+
request_destroy (request);
1373+
future_destroy (future);
13691374

13701375
/* readConcern: { level: futureCompatible } */
13711376
rc = mongoc_read_concern_new ();
@@ -1384,6 +1389,8 @@ test_count_read_concern (void)
13841389
count = future_get_int64_t (future);
13851390
ASSERT_OR_PRINT (count == 45, error);
13861391
mongoc_read_concern_destroy (rc);
1392+
request_destroy (request);
1393+
future_destroy (future);
13871394

13881395
/* Setting readConcern to NULL should not send readConcern */
13891396
rc = mongoc_read_concern_new ();
@@ -1402,6 +1409,8 @@ test_count_read_concern (void)
14021409
count = future_get_int64_t (future);
14031410
ASSERT_OR_PRINT (count == 46, error);
14041411
mongoc_read_concern_destroy (rc);
1412+
request_destroy (request);
1413+
future_destroy (future);
14051414

14061415
/* Fresh read_concern should not send readConcern */
14071416
rc = mongoc_read_concern_new ();
@@ -1418,8 +1427,10 @@ test_count_read_concern (void)
14181427
mock_server_replies_simple (request, "{ 'n' : 47, 'ok' : 1 } ");
14191428
count = future_get_int64_t (future);
14201429
ASSERT_OR_PRINT (count == 47, error);
1421-
mongoc_read_concern_destroy (rc);
14221430

1431+
mongoc_read_concern_destroy (rc);
1432+
request_destroy (request);
1433+
future_destroy (future);
14231434
mongoc_collection_destroy (collection);
14241435
mongoc_client_destroy (client);
14251436
mock_server_destroy (server);
@@ -1708,6 +1719,7 @@ test_aggregate (void)
17081719
ASSERT (!r);
17091720
ASSERT (mongoc_cursor_error (cursor, &error));
17101721
ASSERT (error.code == 16436);
1722+
mongoc_cursor_destroy (cursor);
17111723

17121724
for (i = 0; i < 2; i++) {
17131725
if (i % 2 == 0) {
@@ -2721,6 +2733,7 @@ test_find_read_concern (void)
27212733
future_destroy (future);
27222734
request_destroy (request);
27232735
mongoc_cursor_destroy (cursor);
2736+
mongoc_read_concern_destroy (rc);
27242737

27252738
/* readConcernLevel = random */
27262739
rc = mongoc_read_concern_new ();
@@ -2753,6 +2766,7 @@ test_find_read_concern (void)
27532766
future_destroy (future);
27542767
request_destroy (request);
27552768
mongoc_cursor_destroy (cursor);
2769+
mongoc_read_concern_destroy (rc);
27562770

27572771
/* empty readConcernLevel doesn't send anything */
27582772
rc = mongoc_read_concern_new ();
@@ -2782,6 +2796,7 @@ test_find_read_concern (void)
27822796
future_destroy (future);
27832797
request_destroy (request);
27842798
mongoc_cursor_destroy (cursor);
2799+
mongoc_read_concern_destroy (rc);
27852800

27862801
/* readConcernLevel = NULL doesn't send anything */
27872802
rc = mongoc_read_concern_new ();
@@ -2809,10 +2824,11 @@ test_find_read_concern (void)
28092824
" 'ns': 'test.test',"
28102825
" 'firstBatch': [{'_id': 123}]}}");
28112826
ASSERT (future_get_bool (future));
2827+
28122828
future_destroy (future);
28132829
request_destroy (request);
28142830
mongoc_cursor_destroy (cursor);
2815-
2831+
mongoc_read_concern_destroy (rc);
28162832
mongoc_collection_destroy(collection);
28172833
mongoc_client_destroy(client);
28182834
mock_server_destroy (server);
@@ -2919,7 +2935,7 @@ test_aggregate_read_concern (void)
29192935
request_destroy (request);
29202936
future_destroy (future);
29212937

2922-
2938+
mongoc_read_concern_destroy (rc);
29232939
mongoc_collection_destroy (collection);
29242940
mongoc_client_destroy (client);
29252941
mock_server_destroy (server);

tests/test-mongoc-cursor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ test_kill_cursor_live (void)
220220
MONGOC_ERROR_CURSOR,
221221
16,
222222
"cursor is invalid");
223+
224+
mongoc_cursor_destroy (cursor);
225+
mongoc_bulk_operation_destroy (bulk);
226+
mongoc_collection_destroy (collection);
227+
mongoc_client_destroy (client);
223228
}
224229

225230

tests/test-mongoc-exhaust.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ test_cursor_set_max_await_time_ms (void)
346346
/* once started, cursor ignores set_max_await_time_ms () */
347347
mongoc_cursor_set_max_await_time_ms (cursor, 42);
348348
ASSERT_CMPINT (123, ==, mongoc_cursor_get_max_await_time_ms (cursor));
349+
350+
mongoc_cursor_destroy (cursor);
351+
mongoc_collection_destroy (collection);
352+
mongoc_client_destroy (client);
349353
}
350354

351355
typedef enum

0 commit comments

Comments
 (0)