From 8a9d54df3872175bba774c308dd274ff65be97fe Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Tue, 29 Mar 2005 01:26:27 +0000 Subject: [PATCH] check for malloc failure (also move malloc up to simplify error recovery) Noticed by: Coverity Prevent analysis tool Reviewed by: gnn --- sys/netinet6/raw_ip6.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 2ba558f81b5..cf0e548589f 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -560,6 +560,7 @@ static int rip6_attach(struct socket *so, int proto, struct thread *td) { struct inpcb *inp; + struct icmp6_filter *filter; int error, s; INP_INFO_WLOCK(&ripcbinfo); @@ -577,11 +578,16 @@ rip6_attach(struct socket *so, int proto, struct thread *td) INP_INFO_WUNLOCK(&ripcbinfo); return error; } + MALLOC(filter, struct icmp6_filter *, + sizeof(struct icmp6_filter), M_PCB, M_NOWAIT); + if (filter == NULL) + return ENOMEM; s = splnet(); error = in_pcballoc(so, &ripcbinfo, "raw6inp"); splx(s); if (error) { INP_INFO_WUNLOCK(&ripcbinfo); + FREE(filter, M_PCB); return error; } inp = (struct inpcb *)so->so_pcb; @@ -591,8 +597,7 @@ rip6_attach(struct socket *so, int proto, struct thread *td) inp->in6p_ip6_nxt = (long)proto; inp->in6p_hops = -1; /* use kernel default */ inp->in6p_cksum = -1; - MALLOC(inp->in6p_icmp6filt, struct icmp6_filter *, - sizeof(struct icmp6_filter), M_PCB, M_NOWAIT); + inp->in6p_icmp6filt = filter; ICMP6_FILTER_SETPASSALL(inp->in6p_icmp6filt); INP_UNLOCK(inp); return 0;