From nobody Fri Jun 14 18:09:14 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4W16jk5ymrz5PGpG; Fri, 14 Jun 2024 18:09:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4W16jk5Qk4z48jB; Fri, 14 Jun 2024 18:09:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718388554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XURd3LxFV80GE9oMFQBbJUjUnR0IEeD5M26UTUvfBqg=; b=edgcatkhJTQKka5+4WtCZQ0JcotfQJfN0xRZJcr2HMHA9ltEe6126W2D9JMsI8MW66q2uf nVrZetS43oxJFHxQHdPWIUaKGcuCL0dHzCG/jOycgSv0U0fa5/uwOq/ciba/CXMDCzKzQ6 enYsjCz55PjtDg5t5A6cC3ywcHn7qh1HTcP4KrHS9FSNgpPy0dGsgTDlJzuz0svlOr1g6E Fu+PfMr7aiALUbrf7P9ilapjgvokabJQDDDWwSnXig2LGZqelCZQeWmqDt2G8fWCLrriWx 6/RU856NY6C1fkHRJZ/GvEibOAOCZFVZQL24PQBfJsaXG50EIawIhl7BF4gxWg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718388554; a=rsa-sha256; cv=none; b=ij9z/FSAuWIiN28s/NenY1ZX7N34UJE1XbohoqqkrGTgwWpbDjytwDy26n9y8pAqmaFEHY 3AD8IGXJcSiYK2uRosvs+DB/QSxIUSrfr7YBCCcN+AdoMVStXUXFhoq+Yoi8jH4vU9d8zh UVnebInhKtUpiTuTZDGaAROaQElULYTxtXIrFOzUNEhREU/Z0xOU8/GAY5HF3fJr4/jDdi wOU5YzhP0yVwaT7pi6NnfSTSa0FQPB3zAG+f4SAxjuUHD44lb78kfr3zqhirnDh46s8Tcs lgqiDTsdOyaPYBO2ZMnMM7r08nVZJp4Xmf6uWPhBI8O7bT7gSxJskRm88Cr4rA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718388554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XURd3LxFV80GE9oMFQBbJUjUnR0IEeD5M26UTUvfBqg=; b=uV+lE/IL6shw6c+3G7vXbJSYG4QPK0qZPCPOebvwwoVDCV5TLrIEBa/cM8IKMTvzibMxDr HzxBWU/SPt4PnR9lPL7qTYROsFuW43xERfCUJlhOREjUJIMcNgZhnPkz86pCnjibuMh3WT k8yxtR0Y5Cr2OLTvi9zrnLnCs4DWtORgXAyfp69Vt7ZrETFnqIUhEx5iAM1KjITcHCGl7K 1p/qNLIuQhVBtwE5mbCat7sc8u1aFiu9pYulzGGbRZL2tuXORsfaXskBbfx00eUW240CXF DP9L6U5yQCiHGGOG4TEsgOliUPRAcM6J7Pby84FKYiVKROEygUpNZ2TAolYAbw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4W16jk4vztzWRy; Fri, 14 Jun 2024 18:09:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45EI9EHM054094; Fri, 14 Jun 2024 18:09:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45EI9E80054091; Fri, 14 Jun 2024 18:09:14 GMT (envelope-from git) Date: Fri, 14 Jun 2024 18:09:14 GMT Message-Id: <202406141809.45EI9E80054091@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: 2909ddd17cb4 - main - ctld: plug memory leaks List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2909ddd17cb4d750852dc04128e584f93f8c5058 Auto-Submitted: auto-generated The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=2909ddd17cb4d750852dc04128e584f93f8c5058 commit 2909ddd17cb4d750852dc04128e584f93f8c5058 Author: Alan Somers AuthorDate: 2024-06-12 21:34:05 +0000 Commit: Alan Somers CommitDate: 2024-06-14 18:08:38 +0000 ctld: plug memory leaks MFC after: 2 weeks Reviewed by: mav Sponsored by: Axcient Reported by: valgrind Pull Request: https://github.com/freebsd/freebsd-src/pull/1288 --- usr.sbin/ctld/ctld.c | 1 + usr.sbin/ctld/kernel.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c index c31ac328c84e..bf2791040125 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -2873,6 +2873,7 @@ main(int argc, char **argv) error = conf_apply(oldconf, newconf); if (error != 0) log_warnx("failed to apply configuration"); + conf_delete(newconf); conf_delete(oldconf); oldconf = NULL; diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.c index dd1c89d0e9b8..ae455e7815f7 100644 --- a/usr.sbin/ctld/kernel.c +++ b/usr.sbin/ctld/kernel.c @@ -614,6 +614,22 @@ retry_port: } cp->p_ctl_port = port->port_id; } + while ((port = STAILQ_FIRST(&devlist.port_list))) { + struct cctl_lun_nv *nv; + + STAILQ_REMOVE_HEAD(&devlist.port_list, links); + free(port->port_frontend); + free(port->port_name); + free(port->cfiscsi_target); + free(port->ctld_portal_group_name); + while ((nv = STAILQ_FIRST(&port->attr_list))) { + STAILQ_REMOVE_HEAD(&port->attr_list, links); + free(nv->value); + free(nv->name); + free(nv); + } + free(port); + } free(name); STAILQ_FOREACH(lun, &devlist.lun_list, links) { @@ -664,6 +680,18 @@ retry_port: cl->l_name); } } + while ((lun = STAILQ_FIRST(&devlist.lun_list))) { + struct cctl_lun_nv *nv; + + STAILQ_REMOVE_HEAD(&devlist.lun_list, links); + while ((nv = STAILQ_FIRST(&lun->attr_list))) { + STAILQ_REMOVE_HEAD(&lun->attr_list, links); + free(nv->value); + free(nv->name); + free(nv); + } + free(lun); + } return (conf); } @@ -741,12 +769,14 @@ kernel_lun_add(struct lun *lun) req.args = nvlist_pack(req.args_nvl, &req.args_len); if (req.args == NULL) { + nvlist_destroy(req.args_nvl); log_warn("error packing nvlist"); return (1); } } error = ioctl(ctl_fd, CTL_LUN_REQ, &req); + free(req.args); nvlist_destroy(req.args_nvl); if (error != 0) { @@ -824,12 +854,14 @@ kernel_lun_modify(struct lun *lun) req.args = nvlist_pack(req.args_nvl, &req.args_len); if (req.args == NULL) { + nvlist_destroy(req.args_nvl); log_warn("error packing nvlist"); return (1); } } error = ioctl(ctl_fd, CTL_LUN_REQ, &req); + free(req.args); nvlist_destroy(req.args_nvl); if (error != 0) { @@ -1052,6 +1084,7 @@ kernel_port_add(struct port *port) req.args = nvlist_pack(req.args_nvl, &req.args_len); if (req.args == NULL) { + nvlist_destroy(req.args_nvl); log_warn("error packing nvlist"); return (1); } @@ -1059,6 +1092,7 @@ kernel_port_add(struct port *port) req.result = result_buf; req.result_len = sizeof(result_buf); error = ioctl(ctl_fd, CTL_PORT_REQ, &req); + free(req.args); nvlist_destroy(req.args_nvl); if (error != 0) { @@ -1202,11 +1236,13 @@ kernel_port_remove(struct port *port) req.args = nvlist_pack(req.args_nvl, &req.args_len); if (req.args == NULL) { + nvlist_destroy(req.args_nvl); log_warn("error packing nvlist"); return (1); } error = ioctl(ctl_fd, CTL_PORT_REQ, &req); + free(req.args); nvlist_destroy(req.args_nvl); if (error != 0) {