@@ -129,9 +129,7 @@ mongoc_collection_destroy (mongoc_collection_t *collection) /* IN */
129
129
130
130
bson_return_if_fail (collection );
131
131
132
- if (collection -> gle ) {
133
- bson_destroy (collection -> gle );
134
- }
132
+ bson_clear (& collection -> gle );
135
133
136
134
_mongoc_buffer_destroy (& collection -> buffer );
137
135
@@ -295,14 +293,12 @@ mongoc_collection_find (mongoc_collection_t *collection, /* IN */
295
293
bson_return_val_if_fail (collection , NULL );
296
294
bson_return_val_if_fail (query , NULL );
297
295
296
+ bson_clear (& collection -> gle );
297
+
298
298
if (!read_prefs ) {
299
299
read_prefs = collection -> read_prefs ;
300
300
}
301
301
302
- if (collection -> gle ) {
303
- bson_destroy (collection -> gle );
304
- }
305
-
306
302
return _mongoc_cursor_new (collection -> client , collection -> ns , flags , skip ,
307
303
limit , batch_size , false, query , fields , read_prefs );
308
304
}
@@ -354,9 +350,7 @@ mongoc_collection_command (mongoc_collection_t *collection,
354
350
read_prefs = collection -> read_prefs ;
355
351
}
356
352
357
- if (collection -> gle ) {
358
- bson_destroy (collection -> gle );
359
- }
353
+ bson_clear (& collection -> gle );
360
354
361
355
return mongoc_client_command (collection -> client , collection -> db , flags ,
362
356
skip , limit , batch_size , query , fields , read_prefs );
@@ -372,9 +366,7 @@ mongoc_collection_command_simple (mongoc_collection_t *collection,
372
366
BSON_ASSERT (collection );
373
367
BSON_ASSERT (command );
374
368
375
- if (collection -> gle ) {
376
- bson_destroy (collection -> gle );
377
- }
369
+ bson_clear (& collection -> gle );
378
370
379
371
return mongoc_client_command_simple (collection -> client , collection -> db ,
380
372
command , read_prefs , reply , error );
@@ -680,6 +672,8 @@ _mongoc_collection_insert_bulk_raw (mongoc_collection_t *collection,
680
672
BSON_ASSERT (documents );
681
673
BSON_ASSERT (n_documents );
682
674
675
+ bson_clear (& collection -> gle );
676
+
683
677
if (!write_concern ) {
684
678
write_concern = collection -> write_concern ;
685
679
}
@@ -740,9 +734,6 @@ _mongoc_collection_insert_bulk_raw (mongoc_collection_t *collection,
740
734
bson_init_static (& reply_bson , reply .reply .documents ,
741
735
reply .reply .documents_len );
742
736
743
- if (collection -> gle ) {
744
- bson_destroy (collection -> gle );
745
- }
746
737
collection -> gle = bson_copy (& reply_bson );
747
738
748
739
if (bson_iter_init_find (& reply_iter , & reply_bson , "err" ) &&
@@ -818,6 +809,8 @@ mongoc_collection_insert_bulk (mongoc_collection_t *collection,
818
809
BSON_ASSERT (documents );
819
810
BSON_ASSERT (n_documents );
820
811
812
+ bson_clear (& collection -> gle );
813
+
821
814
if (!(flags & MONGOC_INSERT_NO_VALIDATE )) {
822
815
for (i = 0 ; i < n_documents ; i ++ ) {
823
816
if (!bson_validate (documents [i ],
@@ -901,6 +894,8 @@ mongoc_collection_insert (mongoc_collection_t *collection,
901
894
bson_return_val_if_fail (collection , false);
902
895
bson_return_val_if_fail (document , false);
903
896
897
+ bson_clear (& collection -> gle );
898
+
904
899
if (!bson_iter_init_find (& iter , document , "_id" )) {
905
900
bson_oid_init (& oid , NULL );
906
901
bson_append_oid (& copy , "_id" , 3 , & oid );
@@ -961,6 +956,8 @@ mongoc_collection_update (mongoc_collection_t *collection,
961
956
bson_return_val_if_fail (selector , false);
962
957
bson_return_val_if_fail (update , false);
963
958
959
+ bson_clear (& collection -> gle );
960
+
964
961
if (!(flags & MONGOC_UPDATE_NO_VALIDATE ) &&
965
962
bson_iter_init (& iter , update ) &&
966
963
bson_iter_next (& iter ) &&
@@ -1005,7 +1002,8 @@ mongoc_collection_update (mongoc_collection_t *collection,
1005
1002
}
1006
1003
1007
1004
if (_mongoc_write_concern_has_gle (write_concern )) {
1008
- if (!_mongoc_client_recv_gle (collection , hint , error )) {
1005
+ if (!_mongoc_client_recv_gle (collection -> client , hint ,
1006
+ & collection -> gle , error )) {
1009
1007
RETURN (false);
1010
1008
}
1011
1009
}
@@ -1113,6 +1111,8 @@ mongoc_collection_delete (mongoc_collection_t *collection,
1113
1111
bson_return_val_if_fail (collection , false);
1114
1112
bson_return_val_if_fail (selector , false);
1115
1113
1114
+ bson_clear (& collection -> gle );
1115
+
1116
1116
if (!write_concern ) {
1117
1117
write_concern = collection -> write_concern ;
1118
1118
}
@@ -1136,7 +1136,8 @@ mongoc_collection_delete (mongoc_collection_t *collection,
1136
1136
}
1137
1137
1138
1138
if (_mongoc_write_concern_has_gle (write_concern )) {
1139
- if (!_mongoc_client_recv_gle (collection , hint , error )) {
1139
+ if (!_mongoc_client_recv_gle (collection -> client , hint ,
1140
+ & collection -> gle , error )) {
1140
1141
return false;
1141
1142
}
1142
1143
}
@@ -1294,19 +1295,21 @@ mongoc_collection_get_name (mongoc_collection_t *collection)
1294
1295
* executed command for current collection instance.
1295
1296
*
1296
1297
* Returns:
1297
- * A newly allocated bson_t getLastError document, that *must* be
1298
- * destroyed with bson_destroy(). Or NULL if no getLastError present.
1298
+ * NULL or a bson_t that should not be modified or freed. This value
1299
+ * is not guaranteed to be persistent between calls into the
1300
+ * mongoc_collection_t instance, and therefore must be copied if
1301
+ * you would like to keep it around.
1299
1302
*
1300
1303
* Side effects:
1301
1304
* None.
1302
1305
*
1303
1306
*--------------------------------------------------------------------------
1304
1307
*/
1305
1308
1306
- bson_t *
1307
- mongoc_collection_get_last_error (const mongoc_collection_t * collection )
1309
+ const bson_t *
1310
+ mongoc_collection_get_last_error (const mongoc_collection_t * collection ) /* IN */
1308
1311
{
1309
1312
bson_return_val_if_fail (collection , NULL );
1310
1313
1311
- return collection -> gle ? bson_copy ( collection -> gle ) : NULL ;
1314
+ return collection -> gle ;
1312
1315
}
0 commit comments