-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Trivial - P5
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:
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.