Skip to content

Commit e844510

Browse files
simonbergercopybara-github
authored andcommitted
Fix segmentation faults with enabled keep_descriptor_pool_after_request (#16993)
Fixes #16894 It is tested on command execution only, where it fixes the issues of reported memory leaks, heap corruption and segmentation fault. I could not run tests on my Mac because of #16944 Closes #16993 COPYBARA_INTEGRATE_REVIEW=#16993 from simonberger:bugfix/php-ext-persistent-global-corruption 62b5529 PiperOrigin-RevId: 644034181
1 parent 415a147 commit e844510

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

php/ext/google/protobuf/protobuf.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ static PHP_GINIT_FUNCTION(protobuf) { protobuf_globals->global_symtab = NULL; }
143143
static PHP_RINIT_FUNCTION(protobuf) {
144144
// Create the global generated pool.
145145
// Reuse the symtab (if any) left to us by the last request.
146-
upb_DefPool* symtab = PROTOBUF_G(global_symtab);
147-
if (!symtab) {
148-
PROTOBUF_G(global_symtab) = symtab = upb_DefPool_New();
149-
zend_hash_init(&PROTOBUF_G(name_msg_cache), 64, NULL, NULL, 0);
150-
zend_hash_init(&PROTOBUF_G(name_enum_cache), 64, NULL, NULL, 0);
146+
if (!PROTOBUF_G(global_symtab)) {
147+
zend_bool persistent = PROTOBUF_G(keep_descriptor_pool_after_request);
148+
PROTOBUF_G(global_symtab) = upb_DefPool_New();
149+
zend_hash_init(&PROTOBUF_G(name_msg_cache), 64, NULL, NULL, persistent);
150+
zend_hash_init(&PROTOBUF_G(name_enum_cache), 64, NULL, NULL, persistent);
151151
}
152152

153153
zend_hash_init(&PROTOBUF_G(object_cache), 64, NULL, NULL, 0);
@@ -308,7 +308,7 @@ zend_module_entry protobuf_module_entry = {
308308
protobuf_functions, // function list
309309
PHP_MINIT(protobuf), // process startup
310310
PHP_MSHUTDOWN(protobuf), // process shutdown
311-
PHP_RINIT(protobuf), // request shutdown
311+
PHP_RINIT(protobuf), // request startup
312312
PHP_RSHUTDOWN(protobuf), // request shutdown
313313
NULL, // extension info
314314
PHP_PROTOBUF_VERSION, // extension version

0 commit comments

Comments
 (0)