[CDRIVER-2452] Coverity analysis defect 102207: Resource leak Created: 04/Jan/18  Updated: 28/Oct/23  Resolved: 12/Jan/18

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.10.0

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: Xiangyu Yao (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

Leak of memory or pointers to system resources

Defect 102207 (STATIC_C)
Checker RESOURCE_LEAK (subcategory none)
File: /src/mongoc/mongoc-write-command.c
Function _mongoc_write_opquery
/src/mongoc/mongoc-write-command.c, line: 678
Assigning: "reader" = storage returned from "bson_reader_new_from_data(command->payload.data + data_offset, command->payload.len - data_offset)".

       reader = bson_reader_new_from_data (command->payload.data + data_offset,

/src/mongoc/mongoc-write-command.c, line: 686
Assigning: "bson" = storage returned from "bson_reader_read(reader, &eof)".

       while ((bson = bson_reader_read (reader, &eof))) {

/src/mongoc/mongoc-write-command.c, line: 686
Passing "reader" as argument 1 to function "bson_reader_read", which returns an offset off that argument.

       while ((bson = bson_reader_read (reader, &eof))) {

/src/mongoc/mongoc-write-command.c, line: 686
Resource "reader" is not freed or pointed-to in "bson_reader_read".

       while ((bson = bson_reader_read (reader, &eof))) {

/src/mongoc/mongoc-write-command.c, line: 686
Assigning: "bson" = storage returned from "bson_reader_read(reader, &eof)".

       while ((bson = bson_reader_read (reader, &eof))) {

/src/mongoc/mongoc-write-command.c, line: 698
Resource "bson" is not freed or pointed-to in "bson_append_document".

          BSON_APPEND_DOCUMENT (&ar, key, bson);

/src/mongoc/mongoc-write-command.c, line: 686
Passing "reader" as argument 1 to function "bson_reader_read", which returns an offset off that argument.

       while ((bson = bson_reader_read (reader, &eof))) {

/src/mongoc/mongoc-write-command.c, line: 686
Resource "reader" is not freed or pointed-to in "bson_reader_read".

       while ((bson = bson_reader_read (reader, &eof))) {

/src/mongoc/mongoc-write-command.c, line: 686
Assigning: "bson" = storage returned from "bson_reader_read(reader, &eof)".

       while ((bson = bson_reader_read (reader, &eof))) {

/src/mongoc/mongoc-write-command.c, line: 725
Variable "bson" going out of scope leaks the storage it points to.

             EXIT;

/src/mongoc/mongoc-write-command.c, line: 725
Variable "reader" going out of scope leaks the storage it points to.

             EXIT;

File: /src/mongoc/mongoc-write-command.c
Function _mongoc_write_opquery
/src/mongoc/mongoc-write-command.c, line: 678
Assigning: "reader" = storage returned from "bson_reader_new_from_data(command->payload.data + data_offset, command->payload.len - data_offset)".

       reader = bson_reader_new_from_data (command->payload.data + data_offset,

/src/mongoc/mongoc-write-command.c, line: 686
Assigning: "bson" = storage returned from "bson_reader_read(reader, &eof)".

       while ((bson = bson_reader_read (reader, &eof))) {

/src/mongoc/mongoc-write-command.c, line: 686
Resource "reader" is not freed or pointed-to in "bson_reader_read".

       while ((bson = bson_reader_read (reader, &eof))) {

/src/mongoc/mongoc-write-command.c, line: 725
Variable "reader" going out of scope leaks the storage it points to.

             EXIT;



 Comments   
Comment by Githook User [ 12/Jan/18 ]

Author:

{'email': 'xiangyu.yao24@gmail.com', 'name': 'Xiangyu Yao', 'username': 'xy24'}

Message: CDRIVER-2452 destroy bson_reader before exit
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/1070553880a299c26a2fe8a13a19366673a77155

Generated at Wed Feb 07 21:15:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.