Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-4079

Always initialize reply in stream fetch functions

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Trivial - P5 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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: