com php-src: fix memory errors: phpdbg.c phpdbg.h phpdbg_cmd .c phpdbg_info.c phpdbg_prompt.c
| From: | Bob Weinand | Date: | Mon, 18 Nov 2013 21:59:42 +0000 |
| Subject: | com php-src: fix memory errors: phpdbg.c phpdbg.h phpdbg_cmd .c phpdbg_info.c phpdbg_prompt.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-74829@lists.php.net to get a copy of this message | ||
Commit: a582d2793d490c02ae6ec9a53440363150f29cfc
Author: krakjoe <joe.watkins@live.co.uk> Mon, 18 Nov 2013 21:59:42 +0000
Parents: 9b30877d56fe0f01c0f171eaafd37c967b26ed3e
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a582d2793d490c02ae6ec9a53440363150f29cfc
Log:
fix memory errors
Changed paths:
M phpdbg.c
M phpdbg.h
M phpdbg_cmd.c
M phpdbg_info.c
M phpdbg_prompt.c
Diff:
diff --git a/phpdbg.c b/phpdbg.c
index eaa626d..8393f02 100644
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -599,6 +599,11 @@ phpdbg_main:
/* print blurb */
phpdbg_welcome((cleaning > 0) TSRMLS_CC);
+
+ zend_try {
+ /* activate globals, they can be overwritten */
+ zend_activate_auto_globals(TSRMLS_C);
+ } zend_end_try();
/* initialize from file */
zend_try {
diff --git a/phpdbg.h b/phpdbg.h
index 1a42d0c..15cd1d8 100644
--- a/phpdbg.h
+++ b/phpdbg.h
@@ -96,6 +96,8 @@
#define PHPDBG_IN_LEAVE (1<<15)
#define PHPDBG_SEEK_MASK (PHPDBG_IN_UNTIL|PHPDBG_IN_FINISH|PHPDBG_IN_LEAVE)
+#define PHPDBG_IS_REGISTERED (1<<16)
+
#ifndef _WIN32
# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED)
#else
@@ -115,7 +117,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
int bp_count; /* breakpoint count */
int vmret; /* return from last opcode handler execution */
phpdbg_command_t *lcmd; /* last command */
- phpdbg_param_t lparam; /* last param */
+ phpdbg_param_t lparam; /* last param */
FILE *oplog; /* opline log */
HashTable seek; /* seek oplines */
zend_ulong flags; /* phpdbg flags */
diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c
index a2eb513..6b5eed4 100644
--- a/phpdbg_cmd.c
+++ b/phpdbg_cmd.c
@@ -98,20 +98,23 @@ parsed:
void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */
{
- switch (param->type) {
- case FILE_PARAM:
- efree(param->file.name);
- break;
- case METHOD_PARAM:
- efree(param->method.class);
- efree(param->method.name);
- break;
- case STR_PARAM:
- efree(param->str);
- break;
- default:
- break;
+ if (param) {
+ switch (param->type) {
+ case FILE_PARAM:
+ efree(param->file.name);
+ break;
+ case METHOD_PARAM:
+ efree(param->method..class);
+ efree(param->method.name);
+ break;
+ case STR_PARAM:
+ efree(param->str);
+ break;
+ default:
+ break;
+ }
}
+
} /* }}} */
int phpdbg_do_cmd( const phpdbg_command_t *command, char *cmd_line, size_t cmd_len TSRMLS_DC) /*
{{{ */
@@ -132,19 +135,13 @@ int phpdbg_do_cmd( const phpdbg_command_t *command, char *cmd_line, size_t
cmd_l
if ((command->name_len == expr_len && memcmp(cmd, command->name, expr_len) == 0)
|| (expr_len == 1 && command->alias && command->alias == cmd_line[0])) {
- phpdbg_param_t lparam,
- param;
+ phpdbg_param_t param = {0};
phpdbg_parse_param(
expr,
(cmd_len - expr_len) ? (((cmd_len - expr_len) - sizeof(" "))+1) : 0,
¶m TSRMLS_CC);
- lparam = PHPDBG_G(lparam);
-
- PHPDBG_G(lparam) = param;
- PHPDBG_G(lcmd) = (phpdbg_command_t*) command;
-
if (command->subs && param.type == STR_PARAM) {
if (phpdbg_do_cmd(command->subs, param.str, param.len TSRMLS_CC) == SUCCESS) {
rc = SUCCESS;
@@ -159,10 +156,12 @@ int phpdbg_do_cmd( const phpdbg_command_t *command, char *cmd_line, size_t
cmd_l
phpdbg_error("This command does not expect argument!");
rc = FAILURE;
} else {
- rc = command->handler(¶m TSRMLS_CC);
+ rc = command->handler(
+ ¶m TSRMLS_CC);
+
+ PHPDBG_G(lcmd) = (phpdbg_command_t*) command;
+ PHPDBG_G(lparam) = param;
}
-
- phpdbg_clear_param(&lparam TSRMLS_CC);
break;
}
++command;
diff --git a/phpdbg_info.c b/phpdbg_info.c
index 5f9e196..4b77c61 100644
--- a/phpdbg_info.c
+++ b/phpdbg_info.c
@@ -52,9 +52,10 @@ PHPDBG_INFO(error) /* {{{ */
PHPDBG_INFO(vars) /* {{{ */
{
+ HashTable vars;
HashPosition pos;
char *var;
- zval **data;
+ zval **data, *zdata;
if (!EG(active_symbol_table)) {
zend_rebuild_symbol_table(TSRMLS_C);
@@ -64,25 +65,46 @@ PHPDBG_INFO(vars) /* {{{ */
return SUCCESS;
}
}
-
- phpdbg_notice("Variables: %d",
- zend_hash_num_elements(EG(active_symbol_table)));
-
+ zend_hash_init(&vars, 8, NULL, NULL, 0);
+
zend_hash_internal_pointer_reset_ex(EG(active_symbol_table), &pos);
while (zend_hash_get_current_key_ex(EG(active_symbol_table), &var,
NULL, NULL, 0, &pos) == HASH_KEY_IS_STRING) {
zend_hash_get_current_data_ex(EG(active_symbol_table), (void **)&data, &pos);
-
if (*var != '_') {
- phpdbg_write("Var: %s = ", var, *data == NULL ? "NULL" : "");
- if (data) {
- zend_print_flat_zval_r(*data TSRMLS_CC);
- phpdbg_writeln(EMPTY);
- }
+ zend_hash_update(
+ &vars, var, strlen(var)+1, (void**)data, sizeof(zval*), NULL);
}
zend_hash_move_forward_ex(EG(active_symbol_table), &pos);
}
-
+
+ phpdbg_notice("Variables: %d",
+ zend_hash_num_elements(&vars));
+ phpdbg_writeln("Refs\tName\t\t");
+
+ for (zend_hash_internal_pointer_reset_ex(&vars, &pos);
+ zend_hash_get_current_data_ex(&vars, (void**) &data, &pos) == SUCCESS;
+ zend_hash_move_forward_ex(&vars, &pos)) {
+ char *var;
+ zend_uint var_len;
+ zend_ulong var_idx;
+ zend_hash_get_current_key_ex(&vars, &var, &var_len, &var_idx, 0, &pos);
+
+ if (*data) {
+ phpdbg_write(
+ "%d\t%s$%s\t",
+ Z_REFCOUNT_PP(data),
+ Z_ISREF_PP(data) ? "&" : "", var);
+
+ zend_print_flat_zval_r(*data TSRMLS_CC);
+ } else {
+ phpdbg_write("0\t$%s", var);
+ }
+ phpdbg_writeln(EMPTY);
+ }
+
+ zend_hash_destroy(&vars);
+
return SUCCESS;
} /* }}} */
diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c
index 18aa70b..8e371a2 100644
--- a/phpdbg_prompt.c
+++ b/phpdbg_prompt.c
@@ -464,11 +464,6 @@ static PHPDBG_COMMAND(run) /* {{{ */
zend_rebuild_symbol_table(TSRMLS_C);
}
- zend_try {
- /* last chance ... */
- zend_activate_auto_globals(TSRMLS_C);
- } zend_end_try();
-
/* clean seek state */
PHPDBG_G(flags) &= ~PHPDBG_SEEK_MASK;
zend_hash_clean(