Skip to content

Commit 7add8ae

Browse files
committed
Use common return for zval_to_bson() bsonSerialize() error path
This also initializes ht_data to NULL just to be safe.
1 parent 0b98798 commit 7add8ae

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/bson.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char
767767
PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *bson, bson_t **bson_out TSRMLS_DC) /* {{{ */
768768
{
769769
HashPosition pos;
770-
HashTable *ht_data;
770+
HashTable *ht_data = NULL;
771771
zval *obj_data = NULL;
772772

773773
switch(Z_TYPE_P(data)) {
@@ -777,14 +777,13 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
777777

778778
if (!obj_data) {
779779
/* zend_call_method() failed */
780-
return;
780+
break;
781781
}
782782

783783
if (Z_TYPE_P(obj_data) != IS_ARRAY) {
784784
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Expected %s() to return an array, %s given", BSON_SERIALIZE_FUNC_NAME, zend_get_type_by_const(Z_TYPE_P(obj_data)));
785-
zval_ptr_dtor(&obj_data);
786785

787-
return;
786+
break;
788787
}
789788

790789
ht_data = HASH_OF(obj_data);
@@ -807,7 +806,7 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
807806
return;
808807
}
809808

810-
if (ht_data && ht_data->nApplyCount > 1) {
809+
if (!ht_data || ht_data->nApplyCount > 1) {
811810
if (obj_data) {
812811
zval_ptr_dtor(&obj_data);
813812
}

0 commit comments

Comments
 (0)