{
void *ret;
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
-
+ long * threshold = &MYSQLND_G(debug_emalloc_fail_threshold);
DBG_ENTER(mysqlnd_emalloc_name);
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
- ret = emalloc(REAL_SIZE(size));
+#ifdef PHP_DEBUG
+ /* -1 is also "true" */
+ if (*threshold) {
+#endif
+ ret = emalloc(REAL_SIZE(size));
+#ifdef PHP_DEBUG
+ --*threshold;
+ } else if (*threshold == 0) {
+ ret = NULL;
+ }
+#endif
DBG_INF_FMT("size=%lu ptr=%p", size, ret);
{
void *ret;
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
+ long * threshold = persistent? &MYSQLND_G(debug_malloc_fail_threshold):&MYSQLND_G(debug_emalloc_fail_threshold);
DBG_ENTER(mysqlnd_pemalloc_name);
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
- ret = pemalloc(REAL_SIZE(size), persistent);
+#ifdef PHP_DEBUG
+ /* -1 is also "true" */
+ if (*threshold) {
+#endif
+ ret = pemalloc(REAL_SIZE(size), persistent);
+#ifdef PHP_DEBUG
+ --*threshold;
+ } else if (*threshold == 0) {
+ ret = NULL;
+ }
+#endif
+
DBG_INF_FMT("size=%lu ptr=%p persistent=%d", size, ret, persistent);
if (collect_memory_statistics) {
{
void *ret;
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
+ long * threshold = &MYSQLND_G(debug_ecalloc_fail_threshold);
DBG_ENTER(mysqlnd_ecalloc_name);
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));
- ret = ecalloc(nmemb, REAL_SIZE(size));
+#ifdef PHP_DEBUG
+ /* -1 is also "true" */
+ if (*threshold) {
+#endif
+ ret = ecalloc(nmemb, REAL_SIZE(size));
+#ifdef PHP_DEBUG
+ --*threshold;
+ } else if (*threshold == 0) {
+ ret = NULL;
+ }
+#endif
DBG_INF_FMT("after : %lu", zend_memory_usage(FALSE TSRMLS_CC));
DBG_INF_FMT("size=%lu ptr=%p", size, ret);
{
void *ret;
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
+ long * threshold = persistent? &MYSQLND_G(debug_calloc_fail_threshold):&MYSQLND_G(debug_ecalloc_fail_threshold);
DBG_ENTER(mysqlnd_pecalloc_name);
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
- ret = pecalloc(nmemb, REAL_SIZE(size), persistent);
+#ifdef PHP_DEBUG
+ /* -1 is also "true" */
+ if (*threshold) {
+#endif
+ ret = pecalloc(nmemb, REAL_SIZE(size), persistent);
+#ifdef PHP_DEBUG
+ --*threshold;
+ } else if (*threshold == 0) {
+ ret = NULL;
+ }
+#endif
+
DBG_INF_FMT("size=%lu ptr=%p", size, ret);
if (collect_memory_statistics) {
void *ret;
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
size_t old_size = collect_memory_statistics && ptr? *(size_t *) (((char*)ptr) - sizeof(size_t)) : 0;
+ long * threshold = &MYSQLND_G(debug_erealloc_fail_threshold);
DBG_ENTER(mysqlnd_erealloc_name);
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
DBG_INF_FMT("ptr=%p old_size=%lu, new_size=%lu", ptr, old_size, new_size);
- ret = erealloc(REAL_PTR(ptr), REAL_SIZE(new_size));
+#ifdef PHP_DEBUG
+ /* -1 is also "true" */
+ if (*threshold) {
+#endif
+ ret = erealloc(REAL_PTR(ptr), REAL_SIZE(new_size));
+#ifdef PHP_DEBUG
+ --*threshold;
+ } else if (*threshold == 0) {
+ ret = NULL;
+ }
+#endif
DBG_INF_FMT("new_ptr=%p", (char*)ret);
if (collect_memory_statistics) {
void *ret;
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
size_t old_size = collect_memory_statistics && ptr? *(size_t *) (((char*)ptr) - sizeof(size_t)) : 0;
+ long * threshold = persistent? &MYSQLND_G(debug_realloc_fail_threshold):&MYSQLND_G(debug_erealloc_fail_threshold);
DBG_ENTER(mysqlnd_perealloc_name);
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
DBG_INF_FMT("ptr=%p old_size=%lu new_size=%lu persist=%d", ptr, old_size, new_size, persistent);
- ret = perealloc(REAL_PTR(ptr), REAL_SIZE(new_size), persistent);
+#ifdef PHP_DEBUG
+ /* -1 is also "true" */
+ if (*threshold) {
+#endif
+ ret = perealloc(REAL_PTR(ptr), REAL_SIZE(new_size), persistent);
+#ifdef PHP_DEBUG
+ --*threshold;
+ } else if (*threshold == 0) {
+ ret = NULL;
+ }
+#endif
DBG_INF_FMT("new_ptr=%p", (char*)ret);
{
void *ret;
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
+ long * threshold = &MYSQLND_G(debug_malloc_fail_threshold);
DBG_ENTER(mysqlnd_malloc_name);
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
- ret = malloc(REAL_SIZE(size));
+#ifdef PHP_DEBUG
+ /* -1 is also "true" */
+ if (*threshold) {
+#endif
+ ret = malloc(REAL_SIZE(size));
+#ifdef PHP_DEBUG
+ --*threshold;
+ } else if (*threshold == 0) {
+ ret = NULL;
+ }
+#endif
DBG_INF_FMT("size=%lu ptr=%p", size, ret);
if (collect_memory_statistics) {
{
void *ret;
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
+ long * threshold = &MYSQLND_G(debug_calloc_fail_threshold);
DBG_ENTER(mysqlnd_calloc_name);
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
- ret = calloc(nmemb, REAL_SIZE(size));
+#ifdef PHP_DEBUG
+ /* -1 is also "true" */
+ if (*threshold) {
+#endif
+ ret = calloc(nmemb, REAL_SIZE(size));
+#ifdef PHP_DEBUG
+ --*threshold;
+ } else if (*threshold == 0) {
+ ret = NULL;
+ }
+#endif
DBG_INF_FMT("size=%lu ptr=%p", size, ret);
if (collect_memory_statistics) {
{
void *ret;
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
+ long * threshold = &MYSQLND_G(debug_realloc_fail_threshold);
DBG_ENTER(mysqlnd_realloc_name);
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
DBG_INF_FMT("ptr=%p new_size=%lu ", new_size, ptr);
DBG_INF_FMT("before: %lu", zend_memory_usage(TRUE TSRMLS_CC));
- ret = realloc(REAL_PTR(ptr), REAL_SIZE(new_size));
+#ifdef PHP_DEBUG
+ /* -1 is also "true" */
+ if (*threshold) {
+#endif
+ ret = realloc(REAL_PTR(ptr), REAL_SIZE(new_size));
+#ifdef PHP_DEBUG
+ --*threshold;
+ } else if (*threshold == 0) {
+ ret = NULL;
+ }
+#endif
DBG_INF_FMT("new_ptr=%p", (char*)ret);
mysqlnd_globals->net_read_timeout = 31536000;
mysqlnd_globals->log_mask = 0;
mysqlnd_globals->mempool_default_size = 16000;
+ mysqlnd_globals->debug_emalloc_fail_threshold = -1;
+ mysqlnd_globals->debug_ecalloc_fail_threshold = -1;
+ mysqlnd_globals->debug_erealloc_fail_threshold = -1;
+ mysqlnd_globals->debug_malloc_fail_threshold = -1;
+ mysqlnd_globals->debug_calloc_fail_threshold = -1;
+ mysqlnd_globals->debug_realloc_fail_threshold = -1;
}
/* }}} */
STD_PHP_INI_ENTRY("mysqlnd.net_read_timeout", "31536000", PHP_INI_SYSTEM, OnUpdateLong, net_read_timeout, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.log_mask", "0", PHP_INI_ALL, OnUpdateLong, log_mask, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.mempool_default_size","16000", PHP_INI_ALL, OnUpdateLong, mempool_default_size, zend_mysqlnd_globals, mysqlnd_globals)
+
+#ifdef PHP_DEBUG
+ STD_PHP_INI_ENTRY("mysqlnd.debug_emalloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_emalloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
+ STD_PHP_INI_ENTRY("mysqlnd.debug_ecalloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_ecalloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
+ STD_PHP_INI_ENTRY("mysqlnd.debug_erealloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_erealloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
+
+ STD_PHP_INI_ENTRY("mysqlnd.debug_malloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_malloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
+ STD_PHP_INI_ENTRY("mysqlnd.debug_calloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_calloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
+ STD_PHP_INI_ENTRY("mysqlnd.debug_realloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_realloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
+#endif
PHP_INI_END()
/* }}} */