From nobody Fri Jun 28 19:36:15 2024 X-Original-To: dev-commits-src-all@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 4W9lzg65zvz5PC6j; Fri, 28 Jun 2024 19:36:15 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4W9lzg4QV6z41LW; Fri, 28 Jun 2024 19:36:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1719603375; 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=jbSP/qXz1SoKpmL8O+PC0KnwsV1K0zwRNCgfvV4adZY=; b=dcq9Eoja97G6a4I7kPTtRMDCSnMLmiiITRaKyPSUvs7WpsJuujWT5eb6In6jNsf7Q0Md0a ZfwHLvXuxZ6lkw3jpn8x4Md2p4NlVUjnr0LinixOC53Z9n1tvGK9cNsEXok1t0/sNWrla1 F0ICQH4TcAVHeUzNs+7b4M2bdxmTxqs0mWtS24cU7hpqDScbonNUIf/eLRn+u3Wxza/V59 xIUmZb6A+oOsOqUeHLbiaVvr6iybeOlpKOTc8W0R1bT9iSh057eboP0XSuCTtYap8P17Hd y2YeAnlCcFyImmxORgPm4nEdXazbr51EQxqaLMCmJ/fT+IhUalYJ7w0bRhGUQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1719603375; a=rsa-sha256; cv=none; b=p1Pt+U5PgfEbE1FQd3sZxDtUy5hG4q8v7arcd0YyefrttOF5Q6wrwRovOo+xFnGbstyNoF lhI0MslQul5JWz8s/xWH+FPHdUc0JO43GqjRwPllXc7OLb1QUVFzr30K+GSPZikXNjonne Zpfhr+EuOx8MiqS8OntWUloH8BfMa1JN4dysjQ9M8S9PgJMfB0tCEUawX7YINDLUQnGQ1H ANjsZKWJYBWCILDkNdIwArXfK8rI2TxTVZLV4xYPtkPiSXi4cfq5iNRstrWv34ZslpHo2K 7KbtPLVBmldh+n4b6Aai/jbeFzb2oq7f/MTcrQ7Cz+j1SFFvDb+EOY3yjPlUDw== 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=1719603375; 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=jbSP/qXz1SoKpmL8O+PC0KnwsV1K0zwRNCgfvV4adZY=; b=dK6ZCwWfihxgrbgrDIPZ4/F6ElTcyC51vomzIM8KQQSSbd39t0rsCWsbHgT8CnzpG7BU6t vSEf+LnoupjUpd8C6RfjX4yu0UJytVjo0CIuMt6jmVgBP0toBF7SY4pUFlhKMYmv90akci zN/IxJbMg3b6OlsCMpA06NorZ7SLv0XV4+TbYe4jnmOUBgxBXPCfR9Kt+NNDYWsel9vANy yM+6HnXVJlvq6/CHmnpC76r3VGrqnER5EiyQiGNeAlHg4IOMZNuhamzHOwz2zJqHONwIT9 ItP8L9C+pU56rf8LGXoXTUQ+yHtmh2PYbcsVcp31Y5CtTK2GgtBDQv+VyWzQ7w== 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 4W9lzg42d8z17lY; Fri, 28 Jun 2024 19:36:15 +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 45SJaFS1021212; Fri, 28 Jun 2024 19:36:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45SJaF1J021209; Fri, 28 Jun 2024 19:36:15 GMT (envelope-from git) Date: Fri, 28 Jun 2024 19:36:15 GMT Message-Id: <202406281936.45SJaF1J021209@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: 5d5082fd986e - stable/13 - ctld: plug memory leaks List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 5d5082fd986e11ad5bb30ac82384a28201b260b6 Auto-Submitted: auto-generated The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=5d5082fd986e11ad5bb30ac82384a28201b260b6 commit 5d5082fd986e11ad5bb30ac82384a28201b260b6 Author: Alan Somers AuthorDate: 2024-06-12 21:34:05 +0000 Commit: Alan Somers CommitDate: 2024-06-28 19:35:38 +0000 ctld: plug memory leaks Reviewed by: mav Sponsored by: Axcient Reported by: valgrind Pull Request: https://github.com/freebsd/freebsd-src/pull/1288 (cherry picked from commit 2909ddd17cb4d750852dc04128e584f93f8c5058) --- 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 f2b2de5b9a57..f3d8d5807856 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -2874,6 +2874,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 cbb8e2c25f5d..5ea9295e9df0 100644 --- a/usr.sbin/ctld/kernel.c +++ b/usr.sbin/ctld/kernel.c @@ -615,6 +615,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) { @@ -665,6 +681,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); } @@ -742,12 +770,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) { @@ -825,12 +855,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) { @@ -1053,6 +1085,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); } @@ -1060,6 +1093,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) { @@ -1203,11 +1237,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) {