From: Vladimír Čunát Date: Tue, 1 Jun 2021 14:26:04 +0000 (+0200) Subject: daemon/worker: fix a memory leak X-Git-Tag: v5.4.0~13^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b2ba2d21dd844771586f96d496335ec037dbf1c;p=thirdparty%2Fknot-resolver.git daemon/worker: fix a memory leak Discovered case: TCP write towards upstream fails due to ECONNRESET, and on this place of code we "forget" the whole qr_task and thus its corresponding kr_request, so it remains unanswered and using memory. --- diff --git a/NEWS b/NEWS index 8924e548a..ec47b974c 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ Improvements Bugfixes -------- - trust_anchors.set_insecure: improve precision (#673, !1177) +- plug memory leaks related to TCP (!1182) Incompatible changes -------------------- diff --git a/daemon/worker.c b/daemon/worker.c index f1ade4d25..b97a66c26 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -633,8 +633,22 @@ int qr_task_on_send(struct qr_task *task, const uv_handle_t *handle, int status) } if (handle->type == UV_TCP) { - if (status != 0) - session_tasklist_del(s, task); + if (status != 0) { // session probably not usable anymore; typically: ECONNRESET + if (VERBOSE_STATUS) { + const char *peer_str = NULL; + if (!session_flags(s)->outgoing) { + peer_str = "hidden"; // avoid logging downstream IPs + } else if (task->transport) { + peer_str = kr_straddr(&task->transport->address.ip); + } + if (!peer_str) + peer_str = "unknown"; // probably shouldn't happen + kr_log_verbose( "[wrkr]=> disconnected from '%s': %s\n", + peer_str, uv_strerror(status)); + } + worker_end_tcp(s); + return status; + } if (session_flags(s)->outgoing || session_flags(s)->closing) return status;