[php-src] Issue #14286: ffi enum type make memory leak

From: Date: Tue, 21 May 2024 07:26:06 +0000
Subject: [php-src] Issue #14286: ffi enum type make memory leak
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246937@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/14286 Author: avriltank ### Description The following code: ```php <?php ``` Resulted in this output: ```php <?php $ffi = FFI::cdef(" enum{ //enum TestEnum{ //if enum has a name there is no memory leak TEST_ONE=0, TEST_TWO=1, }; "); echo $ffi->TEST_TWO; //echo 1 //the result is right but memory leak ``` i found the c ffi code when enum has no name make memory leak ``` void zend_ffi_make_enum_type(zend_ffi_dcl *dcl) /* {{{ */ { zend_ffi_type *type = pemalloc(sizeof(zend_ffi_type), FFI_G(persistent)); type->kind = ZEND_FFI_TYPE_ENUM; type->attr = FFI_G(default_type_attr) | (dcl->attr & ZEND_FFI_ENUM_ATTRS); type->enumeration.tag_name = NULL; if (type->attr & ZEND_FFI_ATTR_PACKED) { type->size = zend_ffi_type_uint8.size; type->align = zend_ffi_type_uint8.align; type->enumeration.kind = ZEND_FFI_TYPE_UINT8; } else { type->size = zend_ffi_type_uint32.size; type->align = zend_ffi_type_uint32.align; type->enumeration.kind = ZEND_FFI_TYPE_UINT32; } dcl->type = ZEND_FFI_TYPE_MAKE_OWNED(type); dcl->attr &= ~ZEND_FFI_ENUM_ATTRS; } ``` ![ffi_bad](https://github.com/php/php-src/assets/13652682/be03bf3f-64ac-46f9-b687-41d4b2fe45f2) ### PHP Version php 8.3 ### Operating System windows,linux

« previous php.bugs (#246937) next »