@@ -123,7 +123,11 @@ static void php_phongo_cursor_iterator_move_forward(zend_object_iterator* iter T
123
123
}
124
124
125
125
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
+ }
127
131
} else {
128
132
bson_error_t error = { 0 };
129
133
const bson_t * doc = NULL ;
@@ -164,7 +168,11 @@ static void php_phongo_cursor_iterator_rewind(zend_object_iterator* iter TSRMLS_
164
168
doc = mongoc_cursor_current (cursor -> cursor );
165
169
166
170
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
+ }
168
176
}
169
177
170
178
php_phongo_cursor_free_session_if_exhausted (cursor );
@@ -254,7 +262,9 @@ static PHP_METHOD(Cursor, setTypeMap)
254
262
if (restore_current_element && mongoc_cursor_current (intern -> cursor )) {
255
263
const bson_t * doc = mongoc_cursor_current (intern -> cursor );
256
264
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
+ }
258
268
}
259
269
} /* }}} */
260
270
0 commit comments