Skip to content

Commit

Permalink
Fixed various memory leaks, added dt_destroy_function_data, improved …
Browse files Browse the repository at this point in the history
…performance and method functions
  • Loading branch information
snapserv-bot committed Jan 27, 2013
1 parent d126b50 commit 07d7b37
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 451 deletions.
36 changes: 7 additions & 29 deletions DeepTrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_dt_phpinfo_mode, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_dt_set_proctitle, 0)
ZEND_ARG_INFO(0, "proctitle")
ZEND_ARG_INFO(0, "processTitle")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_dt_exit_mode, 0)
Expand All @@ -58,6 +58,10 @@ ZEND_BEGIN_ARG_INFO(arginfo_dt_rename_function, 0)
ZEND_ARG_INFO(0, "newFunctionName")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_dt_destroy_function_data, 0)
ZEND_ARG_INFO(0, "functionName")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_dt_inspect_zval, 0)
ZEND_ARG_INFO(0, "zval")
ZEND_END_ARG_INFO()
Expand All @@ -76,20 +80,10 @@ ZEND_BEGIN_ARG_INFO(arginfo_dt_destroy_class_data, 0)
ZEND_ARG_INFO(0, "className")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_dt_clear_constant_cache, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_dt_remove_constant, 0)
ZEND_ARG_INFO(0, "constantName")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_dt_get_constant_cache_stats, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_dt_destroy_class_consts, 0)
ZEND_ARG_INFO(0, "className")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_dt_add_method, 0)
ZEND_ARG_INFO(0, "className")
ZEND_ARG_INFO(0, "methodName")
Expand All @@ -115,10 +109,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_dt_set_static_method_variable, 0)
ZEND_ARG_INFO(0, "variableName")
ZEND_ARG_INFO(0, "newValue")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_dt_fix_static_method_calls, 0)
ZEND_ARG_INFO(0, "state")
ZEND_END_ARG_INFO()
/* }}} */

/* {{{ DeepTrace function table */
Expand All @@ -133,21 +123,18 @@ const zend_function_entry DeepTrace_functions[] = {

PHP_FE(dt_remove_function, arginfo_dt_remove_function)
PHP_FE(dt_rename_function, arginfo_dt_rename_function)
PHP_FE(dt_destroy_function_data, arginfo_dt_destroy_function_data)
PHP_FE(dt_set_static_function_variable, arginfo_dt_set_static_function_variable)

PHP_FE(dt_remove_class, arginfo_dt_remove_class)
PHP_FE(dt_destroy_class_data, arginfo_dt_destroy_class_data)

PHP_FE(dt_clear_constant_cache, arginfo_dt_clear_constant_cache)
PHP_FE(dt_remove_constant, arginfo_dt_remove_constant)
PHP_FE(dt_get_constant_cache_stats, arginfo_dt_get_constant_cache_stats)
PHP_FE(dt_destroy_class_consts, arginfo_dt_destroy_class_consts)

PHP_FE(dt_add_method, arginfo_dt_add_method)
PHP_FE(dt_rename_method, arginfo_dt_rename_method)
PHP_FE(dt_remove_method, arginfo_dt_remove_method)
PHP_FE(dt_set_static_method_variable, arginfo_dt_set_static_method_variable)
PHP_FE(dt_fix_static_method_calls, arginfo_dt_fix_static_method_calls)
PHP_FE_END
};
/* }}} */
Expand All @@ -165,7 +152,6 @@ void DeepTrace_init_globals(zend_DeepTrace_globals *globals)

globals->misplaced_internal_functions = NULL;
globals->replaced_internal_functions = NULL;
globals->fixStaticMethodCalls = 1;
}
/* }}} */

Expand Down Expand Up @@ -196,9 +182,6 @@ PHP_MINIT_FUNCTION(DeepTrace)
/* Register opcode handlers */
DEEPTRACE_G(exitOldHandler) = zend_get_user_opcode_handler(ZEND_EXIT);
zend_set_user_opcode_handler(ZEND_EXIT, DeepTrace_exit_handler);
zend_set_user_opcode_handler(ZEND_FETCH_CONSTANT, DeepTrace_constant_handler);
zend_set_user_opcode_handler(ZEND_INIT_STATIC_METHOD_CALL, DeepTrace_static_method_call_handler);
zend_set_user_opcode_handler(ZEND_FETCH_CLASS, DeepTrace_static_method_call_handler);

return SUCCESS;
}
Expand All @@ -208,9 +191,6 @@ PHP_MINIT_FUNCTION(DeepTrace)
PHP_MSHUTDOWN_FUNCTION(DeepTrace)
{
zend_set_user_opcode_handler(ZEND_EXIT, NULL);
zend_set_user_opcode_handler(ZEND_FETCH_CONSTANT, NULL);
zend_set_user_opcode_handler(ZEND_INIT_STATIC_METHOD_CALL, NULL);
zend_set_user_opcode_handler(ZEND_FETCH_CLASS, NULL);

return SUCCESS;
}
Expand All @@ -228,9 +208,7 @@ PHP_RSHUTDOWN_FUNCTION(DeepTrace)
{
DeepTrace_exit_cleanup();
DeepTrace_functions_cleanup();
DeepTrace_constants_cleanup();

DEEPTRACE_G(fixStaticMethodCalls) = 1;
DeepTrace_methods_cleanup();

return SUCCESS;
}
Expand Down
51 changes: 1 addition & 50 deletions DeepTrace_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ PHP_FUNCTION(dt_remove_class)
RETURN_FALSE;
}

DeepTrace_clear_all_functions_runtime_cache(TSRMLS_C);
efree(className);
RETURN_TRUE;
}
Expand Down Expand Up @@ -68,53 +69,3 @@ PHP_FUNCTION(dt_destroy_class_data)
RETURN_TRUE;
}
/* }}} */

/* {{{ DeepTrace_destroy_class_constants */
static int DeepTrace_destroy_class_constants(char *name TSRMLS_DC, int numArgs, va_list args, zend_hash_key *hashKey)
{
DEEPTRACE_DECL_STRING_PARAM(className);
DEEPTRACE_DECL_STRING_PARAM(cacheName);

/* Get arguments */
className = va_arg(args, char *);
className_len = va_arg(args, int);

/* Create combined name */
cacheName = emalloc(className_len + hashKey->nKeyLength + 2);
cacheName_len = className_len + hashKey->nKeyLength + 1;
sprintf(cacheName, "%s::%s", className, hashKey->arKey);

/* Delete constant from constant cache */
#ifdef DEEPTRACE_DEBUG_CONSTANT_CACHE
printf("[DT Constant Cache] Del> %s\n", cacheName);
#endif
zend_hash_del(DEEPTRACE_G(constantCache), cacheName, cacheName_len + 1);
efree(cacheName);

return ZEND_HASH_APPLY_KEEP;
}
/* }}} */

/* {{{ PHP_FUNCTION(dt_destroy_class_consts) */
PHP_FUNCTION(dt_destroy_class_consts)
{
DEEPTRACE_DECL_STRING_PARAM(className);
zend_class_entry **class;

if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", DEEPTRACE_STRING_PARAM(className)) == FAILURE) {
RETURN_FALSE;
}

/* Make class name lowercase */
className = zend_str_tolower_dup(className, className_len);
if(zend_hash_find(EG(class_table), className, className_len + 1, (void **) &class) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class '%s' not found.", className);
efree(className);
RETURN_FALSE;
}

zend_hash_apply_with_arguments(&((zend_class_entry) **class).constants_table,
(apply_func_args_t) DeepTrace_destroy_class_constants, 2, className, className_len);
efree(className);
}
/* }}} */
Loading

0 comments on commit 07d7b37

Please sign in to comment.