Skip to content

Commit cf1bf7b

Browse files
committed
CDRIVER-618 get_collection_names returns NULL on err
1 parent efd15eb commit cf1bf7b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/mongoc/mongoc-database.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ mongoc_database_get_collection_names (mongoc_database_t *database,
826826
mongoc_array_t strv_buf;
827827
mongoc_cursor_t *cursor;
828828
const bson_t *doc;
829+
char **ret;
829830

830831
BSON_ASSERT (database);
831832

@@ -852,9 +853,16 @@ mongoc_database_get_collection_names (mongoc_database_t *database,
852853
namecopy = NULL;
853854
_mongoc_array_append_val (&strv_buf, namecopy);
854855

856+
if (mongoc_cursor_error (cursor, error)) {
857+
_mongoc_array_destroy (&strv_buf);
858+
ret = NULL;
859+
} else {
860+
ret = (char **)strv_buf.data;
861+
}
862+
855863
mongoc_cursor_destroy (cursor);
856864

857-
return (char **) strv_buf.data;
865+
return ret;
858866
}
859867

860868

0 commit comments

Comments
 (0)