diff options
author | Alan Somers <asomers@FreeBSD.org> | 2024-06-12 21:34:05 +0000 |
---|---|---|
committer | Alan Somers <asomers@FreeBSD.org> | 2024-09-19 20:23:53 +0000 |
commit | 0cc98ae442ba4e7764d0d56899fc39f4229a3175 (patch) | |
tree | 3b6fbab17151aa048db7e20c89136e5b55f98ff1 | |
parent | 95fbdf9df5b0918668517298d3ca77b65361b756 (diff) | |
download | src-0cc98ae442ba4e7764d0d56899fc39f4229a3175.tar.gz src-0cc98ae442ba4e7764d0d56899fc39f4229a3175.zip |
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)
-rw-r--r-- | usr.sbin/ctld/ctld.c | 1 | ||||
-rw-r--r-- | usr.sbin/ctld/kernel.c | 36 |
2 files changed, 37 insertions, 0 deletions
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) { |