Skip to content

Commit c6b92f3

Browse files
committed
Merge pull request #1048
2 parents df4474e + 349621a commit c6b92f3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/MongoDB/Cursor.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ static void php_phongo_cursor_iterator_move_forward(zend_object_iterator* iter T
123123
}
124124

125125
if (mongoc_cursor_next(cursor->cursor, &doc)) {
126-
php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &cursor->visitor_data);
126+
if (!php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &cursor->visitor_data)) {
127+
/* Free invalid result, but don't return as we want to free the
128+
* session if the cursor is exhausted. */
129+
php_phongo_cursor_free_current(cursor);
130+
}
127131
} else {
128132
bson_error_t error = { 0 };
129133
const bson_t* doc = NULL;
@@ -164,7 +168,11 @@ static void php_phongo_cursor_iterator_rewind(zend_object_iterator* iter TSRMLS_
164168
doc = mongoc_cursor_current(cursor->cursor);
165169

166170
if (doc) {
167-
php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &cursor->visitor_data);
171+
if (!php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &cursor->visitor_data)) {
172+
/* Free invalid result, but don't return as we want to free the
173+
* session if the cursor is exhausted. */
174+
php_phongo_cursor_free_current(cursor);
175+
}
168176
}
169177

170178
php_phongo_cursor_free_session_if_exhausted(cursor);
@@ -254,7 +262,9 @@ static PHP_METHOD(Cursor, setTypeMap)
254262
if (restore_current_element && mongoc_cursor_current(intern->cursor)) {
255263
const bson_t* doc = mongoc_cursor_current(intern->cursor);
256264

257-
php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &intern->visitor_data);
265+
if (!php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &intern->visitor_data)) {
266+
php_phongo_cursor_free_current(intern);
267+
}
258268
}
259269
} /* }}} */
260270

0 commit comments

Comments
 (0)