@@ -621,6 +621,7 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, php_ph
621
621
php_phongo_writeresult_t * writeresult ;
622
622
zval * zwriteConcern = NULL ;
623
623
const mongoc_write_concern_t * write_concern ;
624
+ bson_t opts = BSON_INITIALIZER ;
624
625
625
626
if (bulk_write -> executed ) {
626
627
phongo_throw_exception (PHONGO_ERROR_WRITE_FAILED TSRMLS_CC , "BulkWrite objects may only be executed once and this instance has already been executed" );
@@ -635,10 +636,13 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, php_ph
635
636
/* FIXME: Legacy way of specifying the writeConcern option into this function */
636
637
if (options && Z_TYPE_P (options ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (options ), php_phongo_writeconcern_ce TSRMLS_CC )) {
637
638
zwriteConcern = options ;
638
- } else if (!phongo_execute_parse_options (client , server_id , options , PHONGO_COMMAND_WRITE , NULL , NULL , & zwriteConcern TSRMLS_CC )) {
639
+ } else if (!phongo_execute_parse_options (client , server_id , options , PHONGO_COMMAND_WRITE , & opts , NULL , & zwriteConcern TSRMLS_CC )) {
640
+ bson_destroy (& opts );
639
641
return false;
640
642
}
641
643
644
+ bson_destroy (& opts );
645
+
642
646
mongoc_bulk_operation_set_database (bulk , bulk_write -> database );
643
647
mongoc_bulk_operation_set_collection (bulk , bulk_write -> collection );
644
648
mongoc_bulk_operation_set_client (bulk , client );
@@ -724,6 +728,7 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, zval *z
724
728
char * collname ;
725
729
mongoc_collection_t * collection ;
726
730
zval * zreadPreference = NULL ;
731
+ bson_t opts = BSON_INITIALIZER ;
727
732
728
733
if (!phongo_split_namespace (namespace , & dbname , & collname )) {
729
734
phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s: %s" , "Invalid namespace provided" , namespace );
@@ -742,10 +747,13 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, zval *z
742
747
/* FIXME: Legacy way of specifying the readPreference option into this function */
743
748
if (options && Z_TYPE_P (options ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (options ), php_phongo_readpreference_ce TSRMLS_CC )) {
744
749
zreadPreference = options ;
745
- } else if (!phongo_execute_parse_options (client , server_id , options , PHONGO_COMMAND_READ , NULL , & zreadPreference , NULL TSRMLS_CC )) {
750
+ } else if (!phongo_execute_parse_options (client , server_id , options , PHONGO_COMMAND_READ , & opts , & zreadPreference , NULL TSRMLS_CC )) {
751
+ bson_destroy (& opts );
746
752
return false;
747
753
}
748
754
755
+ bson_destroy (& opts );
756
+
749
757
cursor = mongoc_collection_find_with_opts (collection , query -> filter , query -> opts , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ));
750
758
mongoc_collection_destroy (collection );
751
759
@@ -791,26 +799,24 @@ int phongo_execute_command(mongoc_client_t *client, php_phongo_command_type_t ty
791
799
bson_iter_t iter ;
792
800
bson_t reply ;
793
801
bson_error_t error ;
794
- bson_t * opts ;
802
+ bson_t opts = BSON_INITIALIZER ;
795
803
mongoc_cursor_t * cmd_cursor ;
796
804
uint32_t selected_server_id ;
797
805
zval * zreadPreference = NULL ;
798
806
int result ;
799
807
800
808
command = Z_COMMAND_OBJ_P (zcommand );
801
809
802
- opts = bson_new ();
803
-
804
810
/* FIXME: Legacy way of specifying the readPreference option into this function */
805
811
if (options && Z_TYPE_P (options ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (options ), php_phongo_readpreference_ce TSRMLS_CC )) {
806
812
zreadPreference = options ;
807
- } else if (!phongo_execute_parse_options (client , server_id , options , type , opts , & zreadPreference , NULL TSRMLS_CC )) {
813
+ } else if (!phongo_execute_parse_options (client , server_id , options , type , & opts , & zreadPreference , NULL TSRMLS_CC )) {
808
814
return false;
809
815
}
810
816
811
- selected_server_id = phongo_do_select_server (client , opts , zreadPreference , server_id TSRMLS_CC );
817
+ selected_server_id = phongo_do_select_server (client , & opts , zreadPreference , server_id TSRMLS_CC );
812
818
if (!selected_server_id ) {
813
- bson_free ( opts );
819
+ bson_destroy ( & opts );
814
820
return false;
815
821
}
816
822
@@ -819,31 +825,31 @@ int phongo_execute_command(mongoc_client_t *client, php_phongo_command_type_t ty
819
825
* command construction. */
820
826
switch (type ) {
821
827
case PHONGO_COMMAND_RAW :
822
- result = mongoc_client_command_with_opts (client , db , command -> bson , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ), opts , & reply , & error );
828
+ result = mongoc_client_command_with_opts (client , db , command -> bson , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ), & opts , & reply , & error );
823
829
break ;
824
830
case PHONGO_COMMAND_READ :
825
- result = mongoc_client_read_command_with_opts (client , db , command -> bson , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ), opts , & reply , & error );
831
+ result = mongoc_client_read_command_with_opts (client , db , command -> bson , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ), & opts , & reply , & error );
826
832
break ;
827
833
case PHONGO_COMMAND_WRITE :
828
- result = mongoc_client_write_command_with_opts (client , db , command -> bson , opts , & reply , & error );
834
+ result = mongoc_client_write_command_with_opts (client , db , command -> bson , & opts , & reply , & error );
829
835
break ;
830
836
case PHONGO_COMMAND_READ_WRITE :
831
837
/* We can pass NULL as readPreference, as this argument was added historically, but has no function */
832
- result = mongoc_client_read_write_command_with_opts (client , db , command -> bson , NULL , opts , & reply , & error );
838
+ result = mongoc_client_read_write_command_with_opts (client , db , command -> bson , NULL , & opts , & reply , & error );
833
839
break ;
834
840
default :
835
841
/* Should never happen, but if it does: exception */
836
842
phongo_throw_exception (PHONGO_ERROR_LOGIC TSRMLS_CC , "Type '%d' should never have been passed to phongo_execute_command, please file a bug report" , type );
837
- bson_free ( opts );
843
+ bson_destroy ( & opts );
838
844
return false;
839
845
}
840
846
if (!result ) {
841
847
phongo_throw_exception_from_bson_error_t (& error TSRMLS_CC );
842
- bson_free ( opts );
848
+ bson_destroy ( & opts );
843
849
return false;
844
850
}
845
851
846
- bson_free ( opts );
852
+ bson_destroy ( & opts );
847
853
848
854
if (!return_value_used ) {
849
855
bson_destroy (& reply );
0 commit comments