@@ -760,6 +760,7 @@ bool phongo_cursor_advance_and_check_for_error(mongoc_cursor_t* cursor TSRMLS_DC
760760bool 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 ) /* {{{ */
761761{
762762 const php_phongo_query_t * query ;
763+ bson_t opts = BSON_INITIALIZER ;
763764 mongoc_cursor_t * cursor ;
764765 char * dbname ;
765766 char * collname ;
@@ -777,30 +778,36 @@ bool phongo_execute_query(mongoc_client_t* client, const char* namespace, zval*
777778
778779 query = Z_QUERY_OBJ_P (zquery );
779780
781+ bson_copy_to (query -> opts , & opts );
782+
780783 if (query -> read_concern ) {
781784 mongoc_collection_set_read_concern (collection , query -> read_concern );
782785 }
783786
784787 if (!phongo_parse_read_preference (options , & zreadPreference TSRMLS_CC )) {
785788 /* Exception should already have been thrown */
786789 mongoc_collection_destroy (collection );
790+ bson_destroy (& opts );
787791 return false;
788792 }
789793
790- if (!phongo_parse_session (options , client , query -> opts , & zsession TSRMLS_CC )) {
794+ if (!phongo_parse_session (options , client , & opts , & zsession TSRMLS_CC )) {
791795 /* Exception should already have been thrown */
792796 mongoc_collection_destroy (collection );
797+ bson_destroy (& opts );
793798 return false;
794799 }
795800
796- if (!BSON_APPEND_INT32 (query -> opts , "serverId" , server_id )) {
801+ if (!BSON_APPEND_INT32 (& opts , "serverId" , server_id )) {
797802 phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Error appending \"serverId\" option" );
798803 mongoc_collection_destroy (collection );
804+ bson_destroy (& opts );
799805 return false;
800806 }
801807
802- cursor = mongoc_collection_find_with_opts (collection , query -> filter , query -> opts , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ));
808+ cursor = mongoc_collection_find_with_opts (collection , query -> filter , & opts , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ));
803809 mongoc_collection_destroy (collection );
810+ bson_destroy (& opts );
804811
805812 /* maxAwaitTimeMS must be set before the cursor is sent */
806813 if (query -> max_await_time_ms ) {
0 commit comments