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

Memory Leaks #190

Closed
rabbiveesh opened this issue Oct 6, 2019 · 3 comments
Closed

Memory Leaks #190

rabbiveesh opened this issue Oct 6, 2019 · 3 comments
Labels
🐞Bug Stuff that doesn't work

Comments

@rabbiveesh
Copy link

rabbiveesh commented Oct 6, 2019

I have the following code (continuing my libpostal saga):

$ffi->attach(
  [ libpostal_get_default_options => 'expansion_defaults' ],
  [], 'expansion_options', );

$ffi->attach(
  [ libpostal_expansion_array_destroy => 'destroy_expansions' ],
  [ opaque => 'size_t' ]);

sub process_char_pp {
  my ($inner, @args) = @_;
  #call the function
  my $ret_ptr = 
    $inner->(@args, \my $ret_len);
  #nothing to do if there are no results
  return () unless $ret_len;
  #cast the char** into an arrayref
  my $ret = $ffi->cast( opaque => "string[$ret_len]", $ret_ptr);
  #clean up the C side of things
  destroy_expansions($ret_ptr, $ret_len);
  #send back the string[]
  return @$ret;
}

sub process_expansions {
  #third arg is the options, if not passed, then supply the
  #defaults
  $_[2] //= expansion_defaults();
  process_char_pp(@_);
}

$ffi->attach(
  [ libpostal_expand_address => 'expand_address' ],
  [ 'string', 'expansion_options', 'size_t*' ], 
  'opaque', \&process_expansions );

The problem I'm having is that none of the things returned from Platypus is ever getting freed. I did a simple test with Test::LeakTrace and it shows that the options struct leaks, as does the arrayref containing the returned strings and the strings themselves. (I also did a overview test, where I ran the function a million times, and continually ate up more and more memory).

Am I missing something? Where is the extra reference to each of these items?

The full code and the test file 't/03-valgrind.t' are in my repo at https://github.com/rabbiveesh/FFI-Postal

@plicease plicease added the 🐞Bug Stuff that doesn't work label Oct 12, 2019
@plicease
Copy link
Member

I believe this is fixed in #191 . I plan on including an exhaustive set of regression tests in that PR.

@rabbiveesh
Copy link
Author

rabbiveesh commented Oct 12, 2019

Yeah, it is! From looking at my tests in Geo::Postal::FFI, the only 'leaks' are things that Platypus is caching. Thank you so much for your tireless work!

@plicease
Copy link
Member

Great. There is another ticket for those leaks, which are less serious, so I'm closing this. This is released as 0.97_05:
https://metacpan.org/release/PLICEASE/FFI-Platypus-0.97_05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞Bug Stuff that doesn't work
Development

No branches or pull requests

2 participants