]> granicus.if.org Git - php/commitdiff
fix memory errors
authorkrakjoe <joe.watkins@live.co.uk>
Mon, 18 Nov 2013 21:59:42 +0000 (21:59 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Mon, 18 Nov 2013 21:59:42 +0000 (21:59 +0000)
phpdbg.c
phpdbg.h
phpdbg_cmd.c
phpdbg_info.c
phpdbg_prompt.c

index eaa626d39a776e31c995f8ebbce9133ac23a366f..8393f02d4ffbb0d5b879195c54622d3f559db6d6 100644 (file)
--- 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 {
index 1a42d0cd85f63fede0fc24da935f034091498579..15cd1d8663a9923c83d571b39204e35a5e7b473f 100644 (file)
--- 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 */
index a2eb51332840681455a540983d65b0d0a123b330..6b5eed43bbbe68e71925b0de8921b651b33faa56 100644 (file)
@@ -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,
                                &param 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(&param TSRMLS_CC);
+                               rc = command->handler(
+                                       &param TSRMLS_CC);
+                               
+                               PHPDBG_G(lcmd) = (phpdbg_command_t*) command;
+                               PHPDBG_G(lparam) = param;
                        }
-                       
-                       phpdbg_clear_param(&lparam TSRMLS_CC);
                        break;
                }
                ++command;
index 5f9e19629a5c9ca8477d196f0b6ef60ea8d97158..4b77c61ea50df6571bef2a3cf5f5f938608da309 100644 (file)
@@ -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;
 } /* }}} */
 
index 18aa70b8d0b9642de36c5c56f895c33a33bf69d1..8e371a22d050848a5bbffef28638de74c1ae3931 100644 (file)
@@ -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(