Permalink
Browse files

[embed] Fix segfault with --leak-test option

Parrot_api_destroy_interpreter can't use the standard EMBED_API_CALLIN,
EMBED_API_CALLOUT macros because the interpreter might be destroyed
when running with --leak-test.
  • Loading branch information...
1 parent 56c6565 commit 2dc51874ffd49e568792b9eac12059358d649c78 @nwellnhof nwellnhof committed Dec 25, 2010
Showing with 22 additions and 5 deletions.
  1. +18 −4 src/embed/api.c
  2. +4 −1 t/run/options.t
View
@@ -282,10 +282,24 @@ Parrot_Int
Parrot_api_destroy_interpreter(Parrot_PMC interp_pmc)
{
ASSERT_ARGS(Parrot_api_destroy_interpreter)
- EMBED_API_CALLIN(interp_pmc, interp)
- Parrot_destroy(interp);
- Parrot_x_exit(interp, 0);
- EMBED_API_CALLOUT(interp_pmc, interp);
+ void * _oldtop;
+ Parrot_jump_buff env;
+ Interp * const interp = GET_INTERP(interp_pmc);
+ _oldtop = interp->lo_var_ptr;
+ if (_oldtop == NULL)
+ interp->lo_var_ptr = &_oldtop;
+ interp->api_jmp_buf = &env;
+ if (setjmp(env)) {
+ /* We can't check for potential errors because the interpreter
+ * might have been destroyed. */
+ return 1;
+ }
+ else {
+ Parrot_destroy(interp);
+ Parrot_x_exit(interp, 0);
+ /* Never reached, x_exit calls longjmp */
+ return 1;
+ }
}
/*
View
@@ -19,7 +19,7 @@ use strict;
use warnings;
use lib qw( lib . ../lib ../../lib );
-use Test::More tests => 30;
+use Test::More tests => 31;
use Parrot::Config;
use File::Temp 0.13 qw/tempfile/;
use File::Spec;
@@ -102,6 +102,9 @@ like( $output, qr/--gc-threshold needs an argument/,
'--gc-threshold needs argument warning' );
is( $exit, 0, '... and should not crash' );
+# Test --leak-test
+is( qx{$PARROT --leak-test "$first_pir_file"}, "first\n", '--leak-test' );
+
# clean up temporary files
unlink $first_pir_file;
unlink $second_pir_file;

0 comments on commit 2dc5187

Please sign in to comment.