If if_attach() failed in the attach function, free resources and return.

This commit is contained in:
msaitoh 2017-10-23 09:32:00 +00:00
parent 916c83ee9b
commit 803d5cc88a
3 changed files with 25 additions and 9 deletions

View File

@ -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 @@ static int
faith_clone_create(struct if_clone *ifc, int unit)
{
struct ifnet *ifp;
int rv;
ifp = if_alloc(IFT_FAITH);
@ -154,7 +155,11 @@ faith_clone_create(struct if_clone *ifc, int unit)
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);

View File

@ -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 @@ static int
loop_clone_create(struct if_clone *ifc, int unit)
{
struct ifnet *ifp;
int rv;
ifp = if_alloc(IFT_LOOP);
@ -195,7 +196,11 @@ loop_clone_create(struct if_clone *ifc, int unit)
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

View File

@ -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 @@ static int
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 @@ mpls_clone_create(struct if_clone *ifc, int unit)
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;