Skip to content

Commit 85e524e

Browse files
committed
Merge pull request #515
2 parents 85562ba + 8456780 commit 85e524e

File tree

9 files changed

+92
-0
lines changed

9 files changed

+92
-0
lines changed

phongo_compat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#endif
8484
# define SIZEOF_PHONGO_LONG SIZEOF_ZEND_LONG
8585
# define phongo_create_object_retval zend_object*
86+
# define phongo_get_gc_table zval **
8687
# define PHONGO_ALLOC_OBJECT_T(_obj_t, _class_type) (_obj_t *)ecalloc(1, sizeof(_obj_t)+zend_object_properties_size(_class_type))
8788
# define PHONGO_TSRMLS_FETCH_FROM_CTX(user_data)
8889
# define SUPPRESS_UNUSED_WARNING(x)
@@ -112,6 +113,7 @@
112113
# define SIZEOF_PHONGO_LONG SIZEOF_LONG
113114
# define ZSTR_VAL(str) str
114115
# define phongo_create_object_retval zend_object_value
116+
# define phongo_get_gc_table zval ***
115117
# define PHONGO_ALLOC_OBJECT_T(_obj_t, _class_type) (_obj_t *)ecalloc(1, sizeof(_obj_t))
116118
# define PHONGO_TSRMLS_FETCH_FROM_CTX(user_data) TSRMLS_FETCH_FROM_CTX(user_data)
117119
# define SUPPRESS_UNUSED_WARNING(x) (void)x;

src/BSON/Binary.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ static int php_phongo_binary_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{
401401
return zend_binary_strcmp(intern1->data, intern1->data_len, intern2->data, intern2->data_len);
402402
} /* }}} */
403403

404+
static HashTable *php_phongo_binary_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
405+
{
406+
*table = NULL;
407+
*n = 0;
408+
409+
return zend_std_get_properties(object TSRMLS_CC);
410+
} /* }}} */
411+
404412
HashTable *php_phongo_binary_get_properties(zval *object TSRMLS_DC) /* {{{ */
405413
{
406414
php_phongo_binary_t *intern;
@@ -458,6 +466,7 @@ PHP_MINIT_FUNCTION(Binary)
458466

459467
memcpy(&php_phongo_handler_binary, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
460468
php_phongo_handler_binary.compare_objects = php_phongo_binary_compare_objects;
469+
php_phongo_handler_binary.get_gc = php_phongo_binary_get_gc;
461470
php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties;
462471
#if PHP_VERSION_ID >= 70000
463472
php_phongo_handler_binary.free_obj = php_phongo_binary_free_object;

src/BSON/Decimal128.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ phongo_create_object_retval php_phongo_decimal128_create_object(zend_class_entry
320320
#endif
321321
} /* }}} */
322322

323+
static HashTable *php_phongo_decimal128_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
324+
{
325+
*table = NULL;
326+
*n = 0;
327+
328+
return zend_std_get_properties(object TSRMLS_CC);
329+
} /* }}} */
330+
323331
HashTable *php_phongo_decimal128_get_properties(zval *object TSRMLS_DC) /* {{{ */
324332
{
325333
php_phongo_decimal128_t *intern;
@@ -372,6 +380,7 @@ PHP_MINIT_FUNCTION(Decimal128)
372380
zend_class_implements(php_phongo_decimal128_ce TSRMLS_CC, 1, zend_ce_serializable);
373381

374382
memcpy(&php_phongo_handler_decimal128, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
383+
php_phongo_handler_decimal128.get_gc = php_phongo_decimal128_get_gc;
375384
php_phongo_handler_decimal128.get_properties = php_phongo_decimal128_get_properties;
376385
#if PHP_VERSION_ID >= 70000
377386
php_phongo_handler_decimal128.free_obj = php_phongo_decimal128_free_object;

src/BSON/Javascript.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,14 @@ static int php_phongo_javascript_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /
443443
return strcmp(intern1->code, intern2->code);
444444
} /* }}} */
445445

446+
static HashTable *php_phongo_javascript_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
447+
{
448+
*table = NULL;
449+
*n = 0;
450+
451+
return zend_std_get_properties(object TSRMLS_CC);
452+
} /* }}} */
453+
446454
HashTable *php_phongo_javascript_get_properties(zval *object TSRMLS_DC) /* {{{ */
447455
{
448456
php_phongo_javascript_t *intern;
@@ -538,6 +546,7 @@ PHP_MINIT_FUNCTION(Javascript)
538546

539547
memcpy(&php_phongo_handler_javascript, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
540548
php_phongo_handler_javascript.compare_objects = php_phongo_javascript_compare_objects;
549+
php_phongo_handler_javascript.get_gc = php_phongo_javascript_get_gc;
541550
php_phongo_handler_javascript.get_properties = php_phongo_javascript_get_properties;
542551
#if PHP_VERSION_ID >= 70000
543552
php_phongo_handler_javascript.free_obj = php_phongo_javascript_free_object;

src/BSON/ObjectID.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,14 @@ static int php_phongo_objectid_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /*
373373
return strcmp(intern1->oid, intern2->oid);
374374
} /* }}} */
375375

376+
static HashTable *php_phongo_objectid_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
377+
{
378+
*table = NULL;
379+
*n = 0;
380+
381+
return zend_std_get_properties(object TSRMLS_CC);
382+
} /* }}} */
383+
376384
HashTable *php_phongo_objectid_get_properties(zval *object TSRMLS_DC) /* {{{ */
377385
{
378386
php_phongo_objectid_t *intern;
@@ -423,6 +431,7 @@ PHP_MINIT_FUNCTION(ObjectID)
423431

424432
memcpy(&php_phongo_handler_objectid, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
425433
php_phongo_handler_objectid.compare_objects = php_phongo_objectid_compare_objects;
434+
php_phongo_handler_objectid.get_gc = php_phongo_objectid_get_gc;
426435
php_phongo_handler_objectid.get_properties = php_phongo_objectid_get_properties;
427436
#if PHP_VERSION_ID >= 70000
428437
php_phongo_handler_objectid.free_obj = php_phongo_objectid_free_object;

src/BSON/Regex.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ static int php_phongo_regex_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{
413413
return strcmp(intern1->flags, intern2->flags);
414414
} /* }}} */
415415

416+
static HashTable *php_phongo_regex_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
417+
{
418+
*table = NULL;
419+
*n = 0;
420+
421+
return zend_std_get_properties(object TSRMLS_CC);
422+
} /* }}} */
423+
416424
HashTable *php_phongo_regex_get_properties(zval *object TSRMLS_DC) /* {{{ */
417425
{
418426
php_phongo_regex_t *intern;
@@ -470,6 +478,7 @@ PHP_MINIT_FUNCTION(Regex)
470478

471479
memcpy(&php_phongo_handler_regex, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
472480
php_phongo_handler_regex.compare_objects = php_phongo_regex_compare_objects;
481+
php_phongo_handler_regex.get_gc = php_phongo_regex_get_gc;
473482
php_phongo_handler_regex.get_properties = php_phongo_regex_get_properties;
474483
#if PHP_VERSION_ID >= 70000
475484
php_phongo_handler_regex.free_obj = php_phongo_regex_free_object;

src/BSON/Timestamp.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ static int php_phongo_timestamp_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /*
439439
return 0;
440440
} /* }}} */
441441

442+
static HashTable *php_phongo_timestamp_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
443+
{
444+
*table = NULL;
445+
*n = 0;
446+
447+
return zend_std_get_properties(object TSRMLS_CC);
448+
} /* }}} */
449+
442450
HashTable *php_phongo_timestamp_get_properties(zval *object TSRMLS_DC) /* {{{ */
443451
{
444452
php_phongo_timestamp_t *intern;
@@ -503,6 +511,7 @@ PHP_MINIT_FUNCTION(Timestamp)
503511

504512
memcpy(&php_phongo_handler_timestamp, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
505513
php_phongo_handler_timestamp.compare_objects = php_phongo_timestamp_compare_objects;
514+
php_phongo_handler_timestamp.get_gc = php_phongo_timestamp_get_gc;
506515
php_phongo_handler_timestamp.get_properties = php_phongo_timestamp_get_properties;
507516
#if PHP_VERSION_ID >= 70000
508517
php_phongo_handler_timestamp.free_obj = php_phongo_timestamp_free_object;

src/BSON/UTCDateTime.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,14 @@ static int php_phongo_utcdatetime_compare_objects(zval *o1, zval *o2 TSRMLS_DC)
490490
return 0;
491491
} /* }}} */
492492

493+
static HashTable *php_phongo_utcdatetime_get_gc(zval *object, phongo_get_gc_table table, int *n TSRMLS_DC) /* {{{ */
494+
{
495+
*table = NULL;
496+
*n = 0;
497+
498+
return zend_std_get_properties(object TSRMLS_CC);
499+
} /* }}} */
500+
493501
HashTable *php_phongo_utcdatetime_get_properties(zval *object TSRMLS_DC) /* {{{ */
494502
{
495503
php_phongo_utcdatetime_t *intern;
@@ -544,6 +552,7 @@ PHP_MINIT_FUNCTION(UTCDateTime)
544552

545553
memcpy(&php_phongo_handler_utcdatetime, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
546554
php_phongo_handler_utcdatetime.compare_objects = php_phongo_utcdatetime_compare_objects;
555+
php_phongo_handler_utcdatetime.get_gc = php_phongo_utcdatetime_get_gc;
547556
php_phongo_handler_utcdatetime.get_properties = php_phongo_utcdatetime_get_properties;
548557
#if PHP_VERSION_ID >= 70000
549558
php_phongo_handler_utcdatetime.free_obj = php_phongo_utcdatetime_free_object;

tests/bson/bug0894-001.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
PHPC-849: BSON get_properties handlers leak during gc_possible_root() checks
3+
--FILE--
4+
<?php
5+
6+
$objects = [
7+
new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC),
8+
new MongoDB\BSON\Decimal128('3.14'),
9+
new MongoDB\BSON\Javascript('function foo() { return bar; }', ['bar' => 42]),
10+
new MongoDB\BSON\MaxKey,
11+
new MongoDB\BSON\MinKey,
12+
new MongoDB\BSON\ObjectID,
13+
new MongoDB\BSON\Regex('foo', 'i'),
14+
new MongoDB\BSON\Timestamp(1234, 5678),
15+
new MongoDB\BSON\UTCDateTime,
16+
];
17+
18+
printf("Created array of %d BSON objects\n", count($objects));
19+
20+
gc_collect_cycles();
21+
22+
?>
23+
===DONE===
24+
<?php exit(0); ?>
25+
--EXPECT--
26+
Created array of 9 BSON objects
27+
===DONE===

0 commit comments

Comments
 (0)