Skip to content

Commit d0ad621

Browse files
committed
Fix further leaks
1 parent d8fe645 commit d0ad621

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

sapi/phpdbg/phpdbg.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
234234
PHPDBG_G(oplog) = NULL;
235235
}
236236

237+
if (PHPDBG_G(ops)) {
238+
destroy_op_array(PHPDBG_G(ops));
239+
efree(PHPDBG_G(ops));
240+
PHPDBG_G(ops) = NULL;
241+
}
242+
237243
if (PHPDBG_G(oplog_list)) {
238244
phpdbg_oplog_list *cur = PHPDBG_G(oplog_list);
239245
do {

sapi/phpdbg/phpdbg_cmd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack) {
396396
case NUMERIC_FUNCTION_PARAM:
397397
case STR_PARAM:
398398
case OP_PARAM:
399+
case EVAL_PARAM:
400+
case SHELL_PARAM:
401+
case COND_PARAM:
402+
case RUN_PARAM:
399403
if (remove->str) {
400404
efree(remove->str);
401405
}

sapi/phpdbg/phpdbg_list.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ zend_op_array *phpdbg_init_compile_file(zend_file_handle *file, int type) {
312312

313313
dataptr->op_array = *op_array;
314314
if (dataptr->op_array.refcount) {
315-
efree(op_array);
315+
++*dataptr->op_array.refcount;
316316
}
317317

318-
return &dataptr->op_array;
318+
return op_array;
319319
}
320320

321321
void phpdbg_free_file_source(zval *zv) {

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,20 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default) /
384384
}
385385
/* }}} */
386386

387+
void phpdbg_clean(zend_bool full) /* {{{ */
388+
{
389+
/* this is implicitly required */
390+
if (PHPDBG_G(ops)) {
391+
destroy_op_array(PHPDBG_G(ops));
392+
efree(PHPDBG_G(ops));
393+
PHPDBG_G(ops) = NULL;
394+
}
395+
396+
if (full) {
397+
PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
398+
}
399+
} /* }}} */
400+
387401
PHPDBG_COMMAND(exec) /* {{{ */
388402
{
389403
zend_stat_t sb;
@@ -409,7 +423,7 @@ PHPDBG_COMMAND(exec) /* {{{ */
409423

410424
if (PHPDBG_G(ops)) {
411425
phpdbg_notice("exec", "type=\"unsetops\"", "Destroying compiled opcodes");
412-
zend_hash_clean(&PHPDBG_G(file_sources));
426+
phpdbg_clean(0);
413427
}
414428

415429
PHPDBG_G(exec) = res;
@@ -423,7 +437,7 @@ PHPDBG_COMMAND(exec) /* {{{ */
423437
phpdbg_notice("exec", "type=\"set\" context=\"%s\"", "Set execution context: %s", PHPDBG_G(exec));
424438

425439
if (PHPDBG_G(in_execution)) {
426-
PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
440+
phpdbg_clean(1);
427441
return SUCCESS;
428442
}
429443

@@ -651,7 +665,7 @@ PHPDBG_COMMAND(run) /* {{{ */
651665
if (PHPDBG_G(in_execution)) {
652666
if (phpdbg_ask_user_permission("Do you really want to restart execution?") == SUCCESS) {
653667
phpdbg_startup_run++;
654-
PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
668+
phpdbg_clean(1);
655669
}
656670
return SUCCESS;
657671
}
@@ -733,7 +747,8 @@ PHPDBG_COMMAND(run) /* {{{ */
733747
}
734748

735749
PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING;
736-
PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
750+
751+
phpdbg_clean(1);
737752
} else {
738753
phpdbg_error("inactive", "type=\"nocontext\"", "Nothing to execute!");
739754
}
@@ -1235,9 +1250,10 @@ PHPDBG_COMMAND(clean) /* {{{ */
12351250
phpdbg_writeln("clean", "constants=\"%d\"", "Constants %d", zend_hash_num_elements(EG(zend_constants)));
12361251
phpdbg_writeln("clean", "includes=\"%d\"", "Includes %d", zend_hash_num_elements(&EG(included_files)));
12371252

1253+
phpdbg_clean(1);
1254+
12381255
phpdbg_xml("</cleaninfo>");
12391256

1240-
PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
12411257
return SUCCESS;
12421258
} /* }}} */
12431259

0 commit comments

Comments
 (0)