Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning function pointers to structs in FFI leaks memory #8433

Closed
bwoebi opened this issue Apr 24, 2022 · 0 comments
Closed

Assigning function pointers to structs in FFI leaks memory #8433

bwoebi opened this issue Apr 24, 2022 · 0 comments

Comments

@bwoebi
Copy link
Member

bwoebi commented Apr 24, 2022

Description

The following code:

<?php

$ffi = FFI::cdef("typedef struct { int a; } bar;");
$x = $ffi->new("bar(*)(void)");
FFI::addr($x)[0] = fn() => $ffi->new("bar");
var_dump($x());

Resulted in these memory leaks:

object(FFI\CData:struct <anonymous>)#5 (1) {
  ["a"]=>
  int(0)
}
[Sun Apr 24 03:13:26 2022]  Script:  'Standard input code'
/Users/bob/php-src/ext/ffi/ffi.c(244) :  Freeing 0x000000010c857400 (88 bytes), script=Standard input code
[Sun Apr 24 03:13:26 2022]  Script:  'Standard input code'
/Users/bob/php-src/ext/ffi/ffi.c(365) :  Freeing 0x000000010c85daf0 (40 bytes), script=Standard input code
=== Total 2 memory leaks detected ===

The first memory leak comes from calling (each call leaks memory - there seems to be a missing zval_ptr_dtor(&retval); in zend_ffi_callback_trampoline).
The second leak comes from the fake struct type not being freed.

PHP Version

master

Operating System

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@cmb69 @bwoebi and others