tcp: improve failure handling in tcp_newtcpcb()

In case of a failure of tcp_newtcpcb, where NULL is returned,
* call CC_ALGO(tp)->cb_destroy, after CC_ALGO(tp)->cb_init was called.
* call khelp_destroy_osd(), after khelp_init_osd() was called.

Reviewed by:		glebius, rscheff
MFC after:		1 week
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D45753
This commit is contained in:
Michael Tuexen 2024-06-27 08:26:34 +02:00
parent a35f665109
commit 14fee5324a

View File

@ -2215,6 +2215,10 @@ tcp_newtcpcb(struct inpcb *inp)
#ifdef TCP_HHOOK
if (khelp_init_osd(HELPER_CLASS_TCP, &tp->t_osd)) {
if (CC_ALGO(tp)->cb_destroy != NULL)
CC_ALGO(tp)->cb_destroy(&tp->t_ccv);
CC_DATA(tp) = NULL;
cc_detach(tp);
if (tp->t_fb->tfb_tcp_fb_fini)
(*tp->t_fb->tfb_tcp_fb_fini)(tp, 1);
refcount_release(&tp->t_fb->tfb_refcnt);
@ -2291,6 +2295,13 @@ tcp_newtcpcb(struct inpcb *inp)
tp->t_pacing_rate = -1;
if (tp->t_fb->tfb_tcp_fb_init) {
if ((*tp->t_fb->tfb_tcp_fb_init)(tp, &tp->t_fb_ptr)) {
if (CC_ALGO(tp)->cb_destroy != NULL)
CC_ALGO(tp)->cb_destroy(&tp->t_ccv);
CC_DATA(tp) = NULL;
cc_detach(tp);
#ifdef TCP_HHOOK
khelp_destroy_osd(&tp->t_osd);
#endif
refcount_release(&tp->t_fb->tfb_refcnt);
return (NULL);
}