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