Source
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s %s", __func__, zbx_result_string(ret), ZBX_NULL2EMPTY_STR(*error));
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the envied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/* maximum number of consequent runtime errors after which it's treated as fatal error */
/******************************************************************************
* *
* Purpose: fatal error handler *
* *
******************************************************************************/
static void es_handle_error(void *udata, const char *msg)
{
zbx_es_env_t *env = (zbx_es_env_t *)udata;
zabbix_log(LOG_LEVEL_WARNING, "Cannot process javascript, fatal error: %s", msg);
env->fatal_error = 1;
env->error = zbx_strdup(env->error, msg);
longjmp(env->loc, 1);
}
/*
* Memory allocation routines to track and limit script memory usage.
*/
static void *es_malloc(void *udata, duk_size_t size)
{
zbx_es_env_t *env = (zbx_es_env_t *)udata;
uint64_t *uptr;
if (env->total_alloc + size + 8 > env->max_total_alloc)
env->max_total_alloc = env->total_alloc + size + 8;
if (env->total_alloc + size + 8 > ZBX_ES_MEMORY_LIMIT)
{
if (NULL == env->ctx)
env->error = zbx_strdup(env->error, "cannot allocate memory");
return NULL;
}
env->total_alloc += (size + 8);
uptr = zbx_malloc(NULL, size + 8);
*uptr++ = size;
return uptr;
}
static void *es_realloc(void *udata, void *ptr, duk_size_t size)
{
zbx_es_env_t *env = (zbx_es_env_t *)udata;
uint64_t *uptr = ptr;
size_t old_size;
if (NULL != uptr)
{
--uptr;