[ZBX-17837] Memory leak when web hook cannot connect to URL Created: 2020 May 28  Updated: 2024 Apr 10  Resolved: 2020 Jun 30

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 5.0.1rc1
Fix Version/s: 5.0.2rc1, 5.2.0alpha1, 5.2 (plan)

Type: Problem report Priority: Trivial
Reporter: Vladislavs Sokurenko Assignee: Andris Zeila
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Causes
caused by ZBX-17227 Webhook media type testing has proble... Closed
Team: Team A
Sprint: Sprint 64 (May 2020), Sprint 65 (Jun 2020)
Story Points: 1

 Description   

Fix:

diff --git a/src/libs/zbxembed/httprequest.c b/src/libs/zbxembed/httprequest.c
index 1ee15ef7a5..060ae792a9 100644
--- a/src/libs/zbxembed/httprequest.c
+++ b/src/libs/zbxembed/httprequest.c
@@ -266,6 +266,8 @@ static duk_ret_t    es_httprequest_query(duk_context *ctx, const char *http_request
 
        if (CURLE_OK != (err = curl_easy_perform(request->handle)))
        {
+               zbx_free(url);  /* free before longjmp()*/
+               zbx_free(contents);
                ret = duk_error(ctx, DUK_RET_TYPE_ERROR, "cannot get URL: %s.", curl_easy_strerror(err));
                goto out;
        }

On media type test:

==125726== HEAP SUMMARY:
==125726==     in use at exit: 387,097 bytes in 7,656 blocks
==125726==   total heap usage: 14,027 allocs, 6,371 frees, 2,107,324 bytes allocated
==125726== 
==125726== 15 bytes in 1 blocks are definitely lost in loss record 23 of 774
==125726==    at 0x483A809: malloc (vg_replace_malloc.c:309)
==125726==    by 0x5D8B9E: zbx_malloc2 (misc.c:575)
==125726==    by 0x5E1ADB: zbx_cesu8_to_utf8 (str.c:2396)
==125726==    by 0x49A96E: es_httprequest_query (httprequest.c:219)
==125726==    by 0x49AE0E: es_httprequest_post (httprequest.c:315)
==125726==    by 0x4DB0AC: duk__handle_call_raw (duktape.c:64989)
==125726==    by 0x4DB444: duk_handle_call_unprotected (duktape.c:65143)
==125726==    by 0x4E8039: duk__executor_handle_call (duktape.c:76454)
==125726==    by 0x4FA79F: duk__js_execute_bytecode_inner (duktape.c:78544)
==125726==    by 0x4E821B: duk_js_execute_bytecode (duktape.c:76729)
==125726==    by 0x4DB04D: duk__handle_call_raw (duktape.c:64967)
==125726==    by 0x4DB444: duk_handle_call_unprotected (duktape.c:65143)
==125726== 
==125726== 116 bytes in 1 blocks are definitely lost in loss record 591 of 774
==125726==    at 0x483A809: malloc (vg_replace_malloc.c:309)
==125726==    by 0x5D8B9E: zbx_malloc2 (misc.c:575)
==125726==    by 0x5E1ADB: zbx_cesu8_to_utf8 (str.c:2396)
==125726==    by 0x49A9DF: es_httprequest_query (httprequest.c:227)
==125726==    by 0x49AE0E: es_httprequest_post (httprequest.c:315)
==125726==    by 0x4DB0AC: duk__handle_call_raw (duktape.c:64989)
==125726==    by 0x4DB444: duk_handle_call_unprotected (duktape.c:65143)
==125726==    by 0x4E8039: duk__executor_handle_call (duktape.c:76454)
==125726==    by 0x4FA79F: duk__js_execute_bytecode_inner (duktape.c:78544)
==125726==    by 0x4E821B: duk_js_execute_bytecode (duktape.c:76729)
==125726==    by 0x4DB04D: duk__handle_call_raw (duktape.c:64967)
==125726==    by 0x4DB444: duk_handle_call_unprotected (duktape.c:65143)

Happens when there is such error

Details Media type test failed.

    Error: cannot get URL: Couldn't connect to server.
    at [anon] (httprequest.c:269) internal
    at [anon] () native strict preventsyield
    at [anon] (function:7) preventsyield
var req = new CurlHttpRequest();
req.SetProxy('socks5h://localhost:1080');
req.AddHeader('Content-Type: application/x-www-form-urlencoded');
 
Zabbix.Log(4, 'webhook request value='+value);
 
req.Post('localhost:8080','payload='+value);
 
Zabbix.Log(4, 'response code: '+req.Status());
 
return JSON.stringify({
  'tags': {
    'endpoint': 'slack'
  }
});


 Comments   
Comment by Andris Zeila [ 2020 Jun 29 ]

Released ZBX-17837 in:

  • pre-5.0.2rc1 a807da8fde, 8d27127cf0
  • pre-5.2.0alpha1 c5ce5256a3, 46e25ed69a
Generated at Sat Dec 13 22:05:04 EET 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.