diff options
Diffstat (limited to 'src/libs/zbxembed/zabbix.c')
-rw-r--r-- | src/libs/zbxembed/zabbix.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/libs/zbxembed/zabbix.c b/src/libs/zbxembed/zabbix.c index ee487552df6..7b7bc8d1094 100644 --- a/src/libs/zbxembed/zabbix.c +++ b/src/libs/zbxembed/zabbix.c @@ -70,7 +70,7 @@ static duk_ret_t es_zabbix_log(duk_context *ctx) { zbx_es_env_t *env; char *message = NULL; - int level; + int level, err_index = -1; duk_memory_functions out_funcs; level = duk_to_int(ctx, 0); @@ -87,9 +87,13 @@ static duk_ret_t es_zabbix_log(duk_context *ctx) env = (zbx_es_env_t *)out_funcs.udata; if (NULL == env->json) + goto out; + + if (ZBX_ES_LOG_MEMORY_LIMIT < env->json->buffer_size) /* approximate limit */ { - zbx_free(message); - return 0; + err_index = duk_push_error_object(ctx, DUK_RET_EVAL_ERROR, "log exceeds the maximum size of " + ZBX_FS_UI64 " bytes.", ZBX_ES_LOG_MEMORY_LIMIT); + goto out; } zbx_json_addobject(env->json, NULL); @@ -97,14 +101,11 @@ static duk_ret_t es_zabbix_log(duk_context *ctx) zbx_json_adduint64(env->json, "ms", zbx_get_duration_ms(&env->start_time)); zbx_json_addstring(env->json, "message", message, ZBX_JSON_TYPE_STRING); zbx_json_close(env->json); - +out: zbx_free(message); - if (ZBX_ES_LOG_MEMORY_LIMIT < env->json->buffer_size) /* approximate limit */ - { - return duk_error(ctx, DUK_RET_TYPE_ERROR, "log exceeds the maximum size of " ZBX_FS_UI64 " bytes.", - ZBX_ES_LOG_MEMORY_LIMIT); - } + if (-1 != err_index) + return duk_throw(ctx); return 0; } |