Skip to content

Commit

Permalink
Fix event_data->e_list management in tgt_event_add to prevent potenti…
Browse files Browse the repository at this point in the history
…al memory leak

Signed-off-by: JK Chen <jk.chen1095@gmail.com>
  • Loading branch information
jkchen1095 committed Aug 10, 2024
1 parent 0984d21 commit 1ccb178
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions usr/tgtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,13 @@ int tgt_event_add(int fd, int events, event_handler_t handler, void *data)
memset(&ev, 0, sizeof(ev));
ev.events = events;
ev.data.ptr = tev;
list_add(&tev->e_list, &tgt_events_list);
err = epoll_ctl(ep_fd, EPOLL_CTL_ADD, fd, &ev);
if (err) {
eprintf("Cannot add fd, %m\n");
list_del(&tev->e_list);
free(tev);
} else
list_add(&tev->e_list, &tgt_events_list);
}

return err;
}
Expand Down

0 comments on commit 1ccb178

Please sign in to comment.