From nobody Thu Sep 19 20:24:50 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 4X8n7R0ktBz5XLQX; Thu, 19 Sep 2024 20:24:51 +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 4X8n7Q68z6z4cn6; Thu, 19 Sep 2024 20:24:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726777490; 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=qxp091VgpZFu9vdCr4iFEg+hbM4P5ylKFU/Jg2yXTik=; b=KrgotSkfbe5xQIoKPwDBtMOtZIBjEX5scau3jCERMjSTrqwWnmuK3JqtvpSuC2egFYVS5Z z8quuDUMT2SKVoXV92Nm0RJCPJwVtjrPJcpGtsAcHo+FxPSSDp4ktzd25bJq8JH4DsxAfr IjtvkAzTRmWvGM+U5tYXpAaOnzvQx4ussQJuqdPMcYFN2tOwCp3aXFdJWwMjB8tCHh6UNc X0hMu6WaavIGfAd8nkgE7CA8meqAm50uLMNH1DaNmkBjNX3qyS90PkYpy6qGxkyFZC60x0 MnPZqzxPZRGFtfZyYe955EHBYkT0HcQocmpF4V4hLrQqffd8w8TOJ13mjfNC0g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726777490; a=rsa-sha256; cv=none; b=M5oJPdh2DYzRCC66yqi80wXaZ+yVQyYVTDZqJzrusYCklQBunGMFk11ZITQ/PDtNKjUJyr yc/UzXHdeOxudE5mAcJ6OHCdf41fpSFZkXL+CpTx0vGsDmC/UKLhtKzb1bZnG+0YrkfS1u 4lCwnwV0sRG12w4o00HYVmhXJb0ms7cBh4LtCgN2srem/rfupqbLW+KOsICsAPCinRFmB4 /Bnh5LniuT05Hc2pYv6iJIgLMMD31cDePMtse80fWuF1ilPAdYdDGc1ZeY7ix6dzkONq+S 2ks4Oxte9cAsdTNi5rfFeTht7Hg0ucTBVaNzQtopw+fw7dEp3kXrq51iVGFIDg== 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=1726777490; 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=qxp091VgpZFu9vdCr4iFEg+hbM4P5ylKFU/Jg2yXTik=; b=Cudrqn0mdxgCj7EBzE+kBeQmbiytqcynWYHV4My2xuSLz5Cfuo08MfZnAkIZIAKaR5zRce 33oHe6Tq6bJ/ZMYzl8HSDEYJWc97+dYuP02nSq9dZr+zANtwf5PI6izoEVhcctwpmJ2WOc ++e95SzrBZe8D6kvCQGzDcixfeufSKy/ei0TZ2wVsztdWrOgqDzMb95V7WD/vP8UGj3YAl 0aPQ6AlpwQVD9Wt87MRFNK+qcXv5MWtobKxjUg1uuG8OBRllZW2+q5zDgZwEoNnroHZCnM obaVfhOSnxS1GR0pFDPZrTymY+/M5OLBL+iHpwbHQjj7ewDfbk11ADh3oSlrYg== 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 4X8n7Q5mnVzKhD; Thu, 19 Sep 2024 20:24:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48JKOoWl052785; Thu, 19 Sep 2024 20:24:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JKOoeB052782; Thu, 19 Sep 2024 20:24:50 GMT (envelope-from git) Date: Thu, 19 Sep 2024 20:24:50 GMT Message-Id: <202409192024.48JKOoeB052782@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: 0cc98ae442ba - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 0cc98ae442ba4e7764d0d56899fc39f4229a3175 Auto-Submitted: auto-generated The branch stable/14 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=0cc98ae442ba4e7764d0d56899fc39f4229a3175 commit 0cc98ae442ba4e7764d0d56899fc39f4229a3175 Author: Alan Somers AuthorDate: 2024-06-12 21:34:05 +0000 Commit: Alan Somers CommitDate: 2024-09-19 20:23:53 +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 ec46a9b765a8..5f61188aa5d6 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) {