Skip to content

Commit 5959c50

Browse files
committed
PHPC-1367: Move libmongoc init/cleanup within scope of custom libbson vtable
1 parent 19cf101 commit 5959c50

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

php_phongo.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3798,11 +3798,12 @@ PHP_MINIT_FUNCTION(mongodb)
37983798

37993799
REGISTER_INI_ENTRIES();
38003800

3801-
/* Initialize libmongoc */
3802-
mongoc_init();
3803-
3804-
/* Initialize libbson */
3801+
/* Assign our custom vtable to libbson, so all memory allocation in libbson
3802+
* (and libmongoc) will use PHP's persistent memory API. After doing so,
3803+
* initialize libmongoc. Later, we will shutdown libmongoc and restore
3804+
* libbson's vtable in the final GSHUTDOWN. */
38053805
bson_mem_set_vtable(&bson_mem_vtable);
3806+
mongoc_init();
38063807

38073808
/* Prep default object handlers to be used when we register the classes */
38083809
memcpy(&phongo_std_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
@@ -3982,8 +3983,8 @@ PHP_GSHUTDOWN_FUNCTION(mongodb)
39823983
* all threads have been destroyed, and it is now safe to shutdown libmongoc
39833984
* and restore libbson's original vtable. */
39843985
if (bson_atomic_int_add(&phongo_num_threads, -1) == 0) {
3985-
bson_mem_restore_vtable();
39863986
mongoc_cleanup();
3987+
bson_mem_restore_vtable();
39873988
}
39883989
}
39893990
/* }}} */

0 commit comments

Comments
 (0)