@@ -807,6 +807,7 @@ bool phongo_cursor_advance_and_check_for_error(mongoc_cursor_t* cursor TSRMLS_DC
807807bool phongo_execute_query (mongoc_client_t * client , const char * namespace , zval * zquery , zval * options , uint32_t server_id , zval * return_value , int return_value_used TSRMLS_DC ) /* {{{ */
808808{
809809 const php_phongo_query_t * query ;
810+ bson_t opts = BSON_INITIALIZER ;
810811 mongoc_cursor_t * cursor ;
811812 char * dbname ;
812813 char * collname ;
@@ -824,30 +825,36 @@ bool phongo_execute_query(mongoc_client_t* client, const char* namespace, zval*
824825
825826 query = Z_QUERY_OBJ_P (zquery );
826827
828+ bson_copy_to (query -> opts , & opts );
829+
827830 if (query -> read_concern ) {
828831 mongoc_collection_set_read_concern (collection , query -> read_concern );
829832 }
830833
831834 if (!phongo_parse_read_preference (options , & zreadPreference TSRMLS_CC )) {
832835 /* Exception should already have been thrown */
833836 mongoc_collection_destroy (collection );
837+ bson_destroy (& opts );
834838 return false;
835839 }
836840
837- if (!phongo_parse_session (options , client , query -> opts , & zsession TSRMLS_CC )) {
841+ if (!phongo_parse_session (options , client , & opts , & zsession TSRMLS_CC )) {
838842 /* Exception should already have been thrown */
839843 mongoc_collection_destroy (collection );
844+ bson_destroy (& opts );
840845 return false;
841846 }
842847
843- if (!BSON_APPEND_INT32 (query -> opts , "serverId" , server_id )) {
848+ if (!BSON_APPEND_INT32 (& opts , "serverId" , server_id )) {
844849 phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Error appending \"serverId\" option" );
845850 mongoc_collection_destroy (collection );
851+ bson_destroy (& opts );
846852 return false;
847853 }
848854
849- cursor = mongoc_collection_find_with_opts (collection , query -> filter , query -> opts , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ));
855+ cursor = mongoc_collection_find_with_opts (collection , query -> filter , & opts , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ));
850856 mongoc_collection_destroy (collection );
857+ bson_destroy (& opts );
851858
852859 /* maxAwaitTimeMS must be set before the cursor is sent */
853860 if (query -> max_await_time_ms ) {
0 commit comments