Skip to content

Commit

Permalink
ctld: plug memory leaks
Browse files Browse the repository at this point in the history
MFC after:	2 weeks
Reviewed by:	mav
Sponsored by:	Axcient
Reported by:	valgrind
Pull Request:	freebsd#1288
  • Loading branch information
asomers committed Jun 14, 2024
1 parent 134f7b5 commit 2909ddd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions usr.sbin/ctld/ctld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
36 changes: 36 additions & 0 deletions usr.sbin/ctld/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,22 @@ conf_new_from_kernel(void)
}
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) {
Expand Down Expand Up @@ -664,6 +680,18 @@ conf_new_from_kernel(void)
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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1052,13 +1084,15 @@ 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);
}

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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2909ddd

Please sign in to comment.