Skip to content

Commit 5607a29

Browse files
committed
CDRIVER-735 segfault in aggregate
And update doc for mongoc_topology_select to warn that some pointer parameters cannot be NULL.
1 parent 14b4f94 commit 5607a29

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/mongoc/mongoc-collection.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,20 @@ mongoc_collection_aggregate (mongoc_collection_t *collection, /* IN */
236236
bson_return_val_if_fail (collection, NULL);
237237
bson_return_val_if_fail (pipeline, NULL);
238238

239+
if (!read_prefs) {
240+
read_prefs = collection->read_prefs;
241+
}
242+
239243
selected_server = mongoc_topology_select(collection->client->topology,
240244
MONGOC_SS_READ,
241245
read_prefs,
242246
15,
243247
&error);
244248

249+
if (!selected_server) {
250+
return NULL;
251+
}
252+
245253
use_cursor = selected_server->max_wire_version >= 1;
246254

247255
bson_init (&command);

src/mongoc/mongoc-topology.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ _mongoc_topology_do_blocking_scan (mongoc_topology_t *topology) {
338338
/*
339339
*-------------------------------------------------------------------------
340340
*
341-
* _mongoc_topology_select --
341+
* mongoc_topology_select --
342342
*
343343
* Selects a server description for an operation based on @optype
344344
* and @read_prefs.
@@ -348,6 +348,15 @@ _mongoc_topology_do_blocking_scan (mongoc_topology_t *topology) {
348348
*
349349
* NOTE: this method locks and unlocks @topology's mutex.
350350
*
351+
* Parameters:
352+
* @topology: The topology.
353+
* @optype: Whether we are selecting for a read or write operation.
354+
* @read_prefs: Required, the read preferences for the command.
355+
* @local_threshold_ms: Maximum latency *beyond* the nearest server
356+
* among which to randomly select servers. See Server Selection
357+
* Spec.
358+
* @error: Required, out pointer for error info.
359+
*
351360
* Returns:
352361
* A mongoc_server_description_t, or NULL on failure, in which case
353362
* @error will be set.

0 commit comments

Comments
 (0)