@@ -55,15 +55,14 @@ static bool php_phongo_document_init_from_hash(php_phongo_document_t* intern, Ha
5555 return false;
5656}
5757
58- static HashTable * php_phongo_document_get_properties_hash (zend_object * object , int size )
58+ static HashTable * php_phongo_document_get_properties_hash (zend_object * object , bool is_temp , int size )
5959{
6060 php_phongo_document_t * intern ;
6161 HashTable * props ;
6262
6363 intern = Z_OBJ_DOCUMENT (object );
6464
65- props = zend_array_dup (zend_std_get_properties (object ));
66- GC_SET_REFCOUNT (props , 0 );
65+ PHONGO_GET_PROPERTY_HASH_INIT_PROPS (is_temp , intern , props , size );
6766
6867 if (!intern -> bson ) {
6968 return props ;
@@ -420,7 +419,7 @@ static PHP_METHOD(MongoDB_BSON_Document, __serialize)
420419{
421420 PHONGO_PARSE_PARAMETERS_NONE ();
422421
423- RETURN_ARR (php_phongo_document_get_properties_hash (Z_OBJ_P (getThis ()), 1 ));
422+ RETURN_ARR (php_phongo_document_get_properties_hash (Z_OBJ_P (getThis ()), true, 1 ));
424423}
425424
426425static PHP_METHOD (MongoDB_BSON_Document , __unserialize )
@@ -446,6 +445,11 @@ static void php_phongo_document_free_object(zend_object* object)
446445 if (intern -> bson ) {
447446 bson_destroy (intern -> bson );
448447 }
448+
449+ if (intern -> properties ) {
450+ zend_hash_destroy (intern -> properties );
451+ FREE_HASHTABLE (intern -> properties );
452+ }
449453}
450454
451455static zend_object * php_phongo_document_create_object (zend_class_entry * class_type )
@@ -494,13 +498,13 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i
494498 php_phongo_document_t * intern ;
495499 HashTable * props ;
496500
497- * is_temp = 0 ;
501+ * is_temp = 1 ;
498502 intern = Z_OBJ_DOCUMENT (object );
499503
500504 /* This get_debug_info handler reports an additional property. This does not
501505 * conflict with other uses of php_phongo_document_get_properties_hash since
502506 * we always allocated a new HashTable with is_temp=true. */
503- props = php_phongo_document_get_properties_hash (object , 2 );
507+ props = php_phongo_document_get_properties_hash (object , true, 2 );
504508
505509 {
506510 php_phongo_bson_state state ;
@@ -510,18 +514,22 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i
510514 state .map .document .type = PHONGO_TYPEMAP_BSON ;
511515 if (!php_phongo_bson_to_zval_ex (intern -> bson , & state )) {
512516 zval_ptr_dtor (& state .zchild );
513- return NULL ;
517+ goto failure ;
514518 }
515519
516520 zend_hash_str_update (props , "value" , sizeof ("value" ) - 1 , & state .zchild );
517521 }
518522
519523 return props ;
524+
525+ failure :
526+ PHONGO_GET_PROPERTY_HASH_FREE_PROPS (is_temp , props );
527+ return NULL ;
520528}
521529
522530static HashTable * php_phongo_document_get_properties (zend_object * object )
523531{
524- return php_phongo_document_get_properties_hash (object , 1 );
532+ return php_phongo_document_get_properties_hash (object , false, 1 );
525533}
526534
527535zval * php_phongo_document_read_property (zend_object * object , zend_string * member , int type , void * * cache_slot , zval * rv )
0 commit comments