diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-06-10 09:13:27 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-06-10 09:13:27 +0000 |
commit | 170804640c53feb6b60b14bae8a8633e8b949911 (patch) | |
tree | bc1a1a9dca7baee7582287f85ddeb282883b0e5f /sys/net/if_bridge.c | |
parent | 8e7db6a9c6de7e28aaf5ac6d45833bf594f45902 (diff) |
prevent mbuf leak on icmp_do_error() failure.
NOTE: under 4.4BSD mbuf coding discipline, once you pass mbuf to a function
like f(m), you no longer have ownership of the mbuf. the mbuf will always
be freed by the called function f(). by keeping the programming rule
you have less chance of memory leak.
Diffstat (limited to 'sys/net/if_bridge.c')
-rw-r--r-- | sys/net/if_bridge.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index d19f2b056b9..d026ec3731e 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bridge.c,v 1.94 2002/06/09 20:30:45 jason Exp $ */ +/* $OpenBSD: if_bridge.c,v 1.95 2002/06/10 09:13:26 itojun Exp $ */ /* * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) @@ -2383,14 +2383,19 @@ bridge_send_icmp_err(sc, ifp, eh, n, hassnap, llc, type, code) struct ip *ip; struct icmp *icp; struct in_addr t; - struct mbuf *m; + struct mbuf *m, *n2; int hlen; u_int8_t ether_tmp[ETHER_ADDR_LEN]; + n2 = m_copym(n, 0, M_COPYALL, M_DONTWAIT); + if (!n2) + return; m = icmp_do_error(n, type, code, 0, ifp); if (m == NULL) return; + n = n2; + ip = mtod(m, struct ip *); hlen = ip->ip_hl << 2; t = ip->ip_dst; |