[CDRIVER-4079] Always initialize reply in stream fetch functions Created: 14/Jul/21  Updated: 15/Apr/22

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

Type: Improvement Priority: Trivial - P5
Reporter: Kevin Albertson Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: CDRIVER-4107

 Description   

Motivation

A common pattern in libmongoc is to initialize an output BSON reply regardless of whether the function call succeeded or failed. This makes it simpler for callers to know how to clean up after:

ok = mongoc_client_command_simple (client, db_name, &cmd, read_prefs, &reply, &error);
 
if (ok) {
    // handle success
} else {
    // handle failure
}
 
bson_destroy (&reply);

The functions following functions do not follow this pattern:

  • mongoc_cluster_stream_for_reads
  • mongoc_cluster_stream_for_writes
  • mongoc_cluster_stream_for_server

They only initialize a BSON reply on failure.

Expecting uninitialized bson_t as an output argument has its own problems (see CDRIVER-3368). But in this case this seems like surprising internal API.

Scope
Modify the above functions to always initialize the bson_t reply on failure and update callers to always call bson_destroy after.


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