diff options
author | arybchik <arybchik@FreeBSD.org> | 2015-03-25 11:01:58 +0000 |
---|---|---|
committer | arybchik <arybchik@FreeBSD.org> | 2015-03-25 11:01:58 +0000 |
commit | 3bb5a2249481904f58fefefc4e7164195d1a331f (patch) | |
tree | c26481efa6e987e824b561f26a55fe88c4d4055f | |
parent | 94a1f15204c91f1864cf52534d134139e740bf69 (diff) | |
download | FreeBSD-src-3bb5a2249481904f58fefefc4e7164195d1a331f.zip FreeBSD-src-3bb5a2249481904f58fefefc4e7164195d1a331f.tar.gz |
MFC: 279097
sfxge: check allocations are non-NULL before freeing them
Caught when efx_filter_init() failed and called efx_filter_fini() in the
teardown path.
Submitted by: Andrew Lee <alee at solarflare.com>
Sponsored by: Solarflare Communications, Inc.
Approved by: gnn (mentor)
-rw-r--r-- | sys/dev/sfxge/common/efx_filter.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/sys/dev/sfxge/common/efx_filter.c b/sys/dev/sfxge/common/efx_filter.c index fa17ae3..a8583b2 100644 --- a/sys/dev/sfxge/common/efx_filter.c +++ b/sys/dev/sfxge/common/efx_filter.c @@ -721,7 +721,7 @@ efx_filter_init( eftp->eft_spec); if (!eftp->eft_spec) { rc = ENOMEM; - goto fail2; + goto fail3; } memset(eftp->eft_spec, 0, eftp->eft_size * sizeof(*eftp->eft_spec)); } @@ -729,6 +729,9 @@ efx_filter_init( return (0); +fail3: + EFSYS_PROBE(fail3); + fail2: EFSYS_PROBE(fail2); efx_filter_fini(enp); @@ -755,12 +758,17 @@ efx_filter_fini( EFX_STATIC_ASSERT(sizeof(eftp->eft_bitmap[0]) == sizeof(uint32_t)); bitmap_size = (eftp->eft_size + (sizeof(uint32_t) * 8) - 1) / 8; - EFSYS_KMEM_FREE(enp->en_esip, bitmap_size, eftp->eft_bitmap); - eftp->eft_bitmap = NULL; + if (eftp->eft_bitmap != NULL) { + EFSYS_KMEM_FREE(enp->en_esip, bitmap_size, + eftp->eft_bitmap); + eftp->eft_bitmap = NULL; + } - EFSYS_KMEM_FREE(enp->en_esip, eftp->eft_size * sizeof(*eftp->eft_spec), - eftp->eft_spec); - eftp->eft_spec = NULL; + if (eftp->eft_spec != NULL) { + EFSYS_KMEM_FREE(enp->en_esip, eftp->eft_size * + sizeof(*eftp->eft_spec), eftp->eft_spec); + eftp->eft_spec = NULL; + } } enp->en_mod_flags &= ~EFX_MOD_FILTER; |