com php-src: Fixed deletion of watchpoints: phpdbg_btree.c phpdbg_watch.c
| From: | Bob Weinand | Date: | Fri, 20 Dec 2013 03:21:08 +0000 |
| Subject: | com php-src: Fixed deletion of watchpoints: phpdbg_btree.c phpdbg_watch.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-77098@lists.php.net to get a copy of this message | ||
Commit: 3f70e9f8bd6e8f7fee4aec65bfb88d81b810c4ea
Author: Bob Weinand <bobwei9@hotmail.com> Thu, 19 Dec 2013 22:21:08 -0500
Parents: 5e351695b6d4ca14c5af7e2690c38c7c07444640
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3f70e9f8bd6e8f7fee4aec65bfb88d81b810c4ea
Log:
Fixed deletion of watchpoints
Changed paths:
M phpdbg_btree.c
M phpdbg_watch.c
Diff:
diff --git a/phpdbg_btree.c b/phpdbg_btree.c
index 21f3fed..6b70d14 100644
--- a/phpdbg_btree.c
+++ b/phpdbg_btree.c
@@ -184,18 +184,24 @@ int phpdbg_btree_delete(phpdbg_btree *tree, zend_ulong idx) {
} while (i--);
if (i_last_dual_branch == -1) {
- efree(tree);
- tree = NULL;
+ efree(tree->branch);
+ tree->branch = NULL;
} else {
if (last_dual_branch->branches[last_dual_branch_branch] == last_dual_branch + 1) {
memcpy(last_dual_branch + 1, last_dual_branch->branches[!last_dual_branch_branch],
i_last_dual_branch * sizeof(phpdbg_btree_branch));
- efree(last_dual_branch->branches[last_dual_branch_branch]);
+ efree(last_dual_branch->branches[!last_dual_branch_branch]);
last_dual_branch->branches[!last_dual_branch_branch] = last_dual_branch + 1;
+
+ branch = last_dual_branch->branches[!last_dual_branch_branch];
+ for (i = i_last_dual_branch; i--;) {
+ branch->branches[!!branch->branches[1]] = last_dual_branch + i_last_dual_branch - i + 1;
+ branch = branch->branches[!!branch->branches[1]];
+ }
} else {
efree(last_dual_branch->branches[last_dual_branch_branch]);
}
- last_dual_branch->branches[i_last_dual_branch] = NULL;
+ last_dual_branch->branches[last_dual_branch_branch] = NULL;
}
return SUCCESS;
diff --git a/phpdbg_watch..c b/phpdbg_watch.c
index 5df867a..0c5eab1 100644
--- a/phpdbg_watch.c
+++ b/phpdbg_watch.c
@@ -48,7 +48,14 @@ static inline size_t phpdbg_get_total_page_size(void *addr, size_t size) {
}
static phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *addr TSRMLS_DC) {
- phpdbg_watchpoint_t *watch = phpdbg_btree_find_closest(&PHPDBG_G(watchpoint_tree),
(zend_ulong)phpdbg_get_page_boundary(addr) + phpdbg_pagesize - 1)->ptr;
+ phpdbg_watchpoint_t *watch;
+ phpdbg_btree_result *result = phpdbg_btree_find_closest(&PHPDBG_G(watchpoint_tree),
(zend_ulong)phpdbg_get_page_boundary(addr) + phpdbg_pagesize - 1);
+
+ if (result == NULL) {
+ return NULL;
+ }
+
+ watch = result->ptr;
/* check if that addr is in a mprotect()'ed memory area */
if ((char *)phpdbg_get_page_boundary(watch->addr.ptr) > (char *)addr || (char
*)phpdbg_get_page_boundary(watch->addr.ptr) + phpdbg_get_total_page_size(watch->addr.ptr,
watch->size) < (char *)addr) {
@@ -161,7 +168,8 @@ static int phpdbg_watchpoint_parse_input(char *input, size_t len, HashTable *par
phpdbg_watchpoint_t *watch = emalloc(sizeof(phpdbg_watchpoint_t));
zend_hash_get_current_key_zval_ex(parent, key, &position);
convert_to_string(key);
- watch->str_len = asprintf(&watch->str, "%.*s%.*s%s", i, input,
Z_STRLEN_P(key), Z_STRVAL_P(key), input[len - 1] == ']'?"]":"");
+ watch->str = emalloc(i + Z_STRLEN_P(key) + 2);
+ watch->str_len = sprintf(watch->str, "%.*s%.*s%s", i, input, Z_STRLEN_P(key),
Z_STRVAL_P(key), input[len - 1] == ']'?"]":"");
efree(key);
watch->name_in_parent = estrndup(last_index, index_len);
watch->name_in_parent_len = index_len;
@@ -284,7 +292,7 @@ void phpdbg_watchpoints_clean(TSRMLS_DC) {
static void phpdbg_watch_dtor(void *pDest) {
TSRMLS_FETCH();
- phpdbg_watchpoint_t *watch = (phpdbg_watchpoint_t *)pDest;
+ phpdbg_watchpoint_t *watch = *(phpdbg_watchpoint_t **)pDest;
phpdbg_deactivate_watchpoint(watch);
phpdbg_btree_delete(&PHPDBG_G(watchpoint_tree), (zend_ulong)watch->addr.ptr);