Skip to content
This repository was archived by the owner on Jan 14, 2023. It is now read-only.

Commit 39d5cc6

Browse files
authored
Fix segfault on OSX (#42)
1 parent 2e46430 commit 39d5cc6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stackdriver_debugger_ast.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ static int compile_ast(zend_string *source, zend_ast **ast_p, zend_lex_state *or
350350
zval source_zval;
351351

352352
ZVAL_STR(&source_zval, source);
353+
Z_TRY_ADDREF(source_zval);
353354
zend_save_lexical_state(original_lex_state);
354355

355356
if (zend_prepare_string_for_scanning(&source_zval, "") == FAILURE) {
@@ -527,7 +528,8 @@ static int valid_debugger_ast(zend_ast *ast)
527528
int valid_debugger_statement(zend_string *statement)
528529
{
529530
zend_lex_state original_lex_state;
530-
zend_ast *ast_p;
531+
zend_ast *ast_p, *old_ast = CG(ast);
532+
zend_arena *old_arena = CG(ast_arena);
531533

532534
/*
533535
* Append ';' to the end for lexing/parsing. Evaluating the statement
@@ -555,8 +557,8 @@ int valid_debugger_statement(zend_string *statement)
555557
zend_ast_destroy(CG(ast));
556558
zend_arena_destroy(CG(ast_arena));
557559
zend_restore_lexical_state(&original_lex_state);
558-
CG(ast) = NULL;
559-
CG(ast_arena) = NULL;
560+
CG(ast) = old_ast;
561+
CG(ast_arena) = old_arena;
560562

561563
return SUCCESS;
562564
}

0 commit comments

Comments
 (0)