run4flat / C-Blocks

Embeding a fast C compiler directly into your Perl parser
30 stars 3 forks source link

C::Blocks leaks on compiler errors #10

Closed tsee closed 7 years ago

tsee commented 7 years ago

Right now, C::Blocks will leak its internal state whenever there's an exception thrown in the keyword plugin.

The following commit (which might not cleanly apply to master since it's based off of the tsee/mutex branch) fixes one of several such leaks:

https://github.com/tsee/C-Blocks/commit/d14433453ad22b54453583e9c0d293cf802c970d

If I get some spare time I'll try to fix more of them, but in a nutshell, this shows the problem:

use strict;use warnings;use C::Blocks;
cblock {
  int i
}

Run that with valgrind after adding the missing semicolon. Note the leaks. Then run it as is. According to my machine, 11 more leaks (though they might end up pointing to the same one or two root causes).

The commit above fixes some of them by making sure cleanup_c_blocks_data gets called even on croak().

--Steffen

tsee commented 7 years ago

This is somewhat superseded by https://github.com/run4flat/C-Blocks/pull/12

tsee commented 7 years ago

I just reran valgrind with my stock distribution 5.22.1 and a threaded debugging build of blead. For blead, valgrind shows no more leaks remaining after this change set and the simple test script above. 5.22.1 still shows a number of leaks, but those aren't obviously coming from the same logical source. So for the time being until either of us digs up other evidence of leaks, I'm closing this.