mongodb/mongo-c-driver — pull request #160 by jsbattig (2013-11-27 22:29:53+00:00)
Title: Fixed access violation when killing primary replica

In a situation of heavy traffic reading from a capped collection if a primary node on a replicaset is killed driver is left with a reply pointer in cursor object with a dangling pointer.

This piece of code:

```
...
data = mongo_data_append( data, cursor->ns, sl );
data = mongo_data_append32( data, &limit );
mongo_data_append64( data, &cursor->reply->fields.cursorID );

bson_free( cursor->reply ); /* This creates dangling pointer */

res = mongo_message_send( cursor->conn, mm ); /* This operation fails when primary is dead, leaving cursor->reply dangling */
if( res != MONGO_OK ) {
mongo_cursor_destroy( cursor );
return MONGO_ERROR;
}
...
```

Needs to be changed to avoid dangling pointer.