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

Clarify calling codes cleanup responsibilities when mongoc_collection_find_and_modify returns false

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.9.0
    • Affects Version/s: 1.4.1
    • Component/s: None
    • None

      Prior to CDRIVER-1381 the reply bson_t was not initialized if mongoc_collection_find_and_modify() returned false. To prevent badness client code needed to effectively do something like:

      old way
         bool ok;
         bson_t reply;
      
         ok = mongoc_collection_find_and_modify (collection, query, NULL, update, NULL, false, false, true, &reply, &error);
      
         if(ok) {
             bson_destroy(&reply);
         }
      

      Now the reply bson_t is always initialized regardless of the return value of mongoc_collection_find_and_modify(). Based on the comment for the change it does not seem like this was intended. Is this new behavior a bug? Should client code like the code above? Or like the code below?

      new way?
         bool ok;
         bson_t reply;
      
         ok = mongoc_collection_find_and_modify (collection, query, NULL, update, NULL, false, false, true, &reply, &error);
      
         bson_destroy(&reply);
      

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            gbw4th Graham Whitted
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: