Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net If if_attach() failed in the attach function, free r...
details: https://anonhg.NetBSD.org/src/rev/49f83decc38e
branches: trunk
changeset: 357015:49f83decc38e
user: msaitoh <msaitoh%NetBSD.org@localhost>
date: Mon Oct 23 09:32:00 2017 +0000
description:
If if_attach() failed in the attach function, free resources and return.
diffstat:
sys/net/if_faith.c | 11 ++++++++---
sys/net/if_loop.c | 11 ++++++++---
sys/net/if_mpls.c | 12 +++++++++---
3 files changed, 25 insertions(+), 9 deletions(-)
diffs (118 lines):
diff -r a51f63ccaddf -r 49f83decc38e sys/net/if_faith.c
--- a/sys/net/if_faith.c Mon Oct 23 09:31:17 2017 +0000
+++ b/sys/net/if_faith.c Mon Oct 23 09:32:00 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_faith.c,v 1.55 2016/12/12 03:55:57 ozaki-r Exp $ */
+/* $NetBSD: if_faith.c,v 1.56 2017/10/23 09:32:00 msaitoh Exp $ */
/* $KAME: if_faith.c,v 1.21 2001/02/20 07:59:26 itojun Exp $ */
/*
@@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.55 2016/12/12 03:55:57 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.56 2017/10/23 09:32:00 msaitoh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -140,6 +140,7 @@
faith_clone_create(struct if_clone *ifc, int unit)
{
struct ifnet *ifp;
+ int rv;
ifp = if_alloc(IFT_FAITH);
@@ -154,7 +155,11 @@
ifp->if_hdrlen = 0;
ifp->if_addrlen = 0;
ifp->if_dlt = DLT_NULL;
- if_attach(ifp);
+ rv = if_attach(ifp);
+ if (rv != 0) {
+ if_free(ifp);
+ return rv;
+ }
if_alloc_sadl(ifp);
bpf_attach(ifp, DLT_NULL, sizeof(u_int));
atomic_inc_uint(&faith_count);
diff -r a51f63ccaddf -r 49f83decc38e sys/net/if_loop.c
--- a/sys/net/if_loop.c Mon Oct 23 09:31:17 2017 +0000
+++ b/sys/net/if_loop.c Mon Oct 23 09:32:00 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_loop.c,v 1.95 2017/09/21 11:42:17 knakahara Exp $ */
+/* $NetBSD: if_loop.c,v 1.96 2017/10/23 09:32:00 msaitoh Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.95 2017/09/21 11:42:17 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.96 2017/10/23 09:32:00 msaitoh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -175,6 +175,7 @@
loop_clone_create(struct if_clone *ifc, int unit)
{
struct ifnet *ifp;
+ int rv;
ifp = if_alloc(IFT_LOOP);
@@ -195,7 +196,11 @@
IFQ_SET_READY(&ifp->if_snd);
if (unit == 0)
lo0ifp = ifp;
- if_attach(ifp);
+ rv = if_attach(ifp);
+ if (rv != 0) {
+ if_free(ifp);
+ return rv;
+ }
if_alloc_sadl(ifp);
bpf_attach(ifp, DLT_NULL, sizeof(u_int));
#ifdef MBUFTRACE
diff -r a51f63ccaddf -r 49f83decc38e sys/net/if_mpls.c
--- a/sys/net/if_mpls.c Mon Oct 23 09:31:17 2017 +0000
+++ b/sys/net/if_mpls.c Mon Oct 23 09:32:00 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_mpls.c,v 1.29 2016/12/12 03:55:57 ozaki-r Exp $ */
+/* $NetBSD: if_mpls.c,v 1.30 2017/10/23 09:32:00 msaitoh Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.29 2016/12/12 03:55:57 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.30 2017/10/23 09:32:00 msaitoh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -149,6 +149,7 @@
mpls_clone_create(struct if_clone *ifc, int unit)
{
struct mpls_softc *sc;
+ int rv;
atomic_inc_uint(&mpls_count);
sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
@@ -165,7 +166,12 @@
sc->sc_if.if_output = mpls_output;
sc->sc_if.if_ioctl = mpls_ioctl;
- if_attach(&sc->sc_if);
+ rv = if_attach(&sc->sc_if);
+ if (rv != 0) {
+ free(sc, M_DEVBUF);
+ atomic_dec_uint(&mpls_count);
+ return rv;
+ }
if_alloc_sadl(&sc->sc_if);
bpf_attach(&sc->sc_if, DLT_NULL, sizeof(uint32_t));
return 0;
Home |
Main Index |
Thread Index |
Old Index