From owner-svn-src-head@FreeBSD.ORG Tue Dec 18 08:53:08 2012 Return-Path: Delivered-To: svn-src-head@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 62585184; Tue, 18 Dec 2012 08:53:08 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebius.int.ru (glebius.int.ru [81.19.69.10]) by mx1.freebsd.org (Postfix) with ESMTP id B8AA38FC13; Tue, 18 Dec 2012 08:53:07 +0000 (UTC) Received: from cell.glebius.int.ru (localhost [127.0.0.1]) by cell.glebius.int.ru (8.14.5/8.14.5) with ESMTP id qBI8r6P6062205; Tue, 18 Dec 2012 12:53:06 +0400 (MSK) (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by cell.glebius.int.ru (8.14.5/8.14.5/Submit) id qBI8r6DS062204; Tue, 18 Dec 2012 12:53:06 +0400 (MSK) (envelope-from glebius@FreeBSD.org) X-Authentication-Warning: cell.glebius.int.ru: glebius set sender to glebius@FreeBSD.org using -f Date: Tue, 18 Dec 2012 12:53:06 +0400 From: Gleb Smirnoff To: Monthadar Al Jaberi Subject: Re: svn commit: r244389 - head/sys/dev/wtap Message-ID: <20121218085306.GK94420@FreeBSD.org> References: <201212180844.qBI8ixdX097633@svn.freebsd.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="UlVJffcvxoiEqYs2" Content-Disposition: inline In-Reply-To: <201212180844.qBI8ixdX097633@svn.freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Dec 2012 08:53:08 -0000 --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Monthadar, On Tue, Dec 18, 2012 at 08:44:59AM +0000, Monthadar Al Jaberi wrote: M> Author: monthadar M> Date: Tue Dec 18 08:44:59 2012 M> New Revision: 244389 M> URL: http://svnweb.freebsd.org/changeset/base/244389 M> M> Log: M> wtap should check if ieee80211_vap_setup fails. M> M> * If ieee80211_vap_setup fails, we free allocated M_80211_VAP M> memory and return NULL; M> M> Approved by: adrian (mentor) M> M> Modified: M> head/sys/dev/wtap/if_wtap.c M> M> Modified: head/sys/dev/wtap/if_wtap.c M> ============================================================================== M> --- head/sys/dev/wtap/if_wtap.c Tue Dec 18 08:41:23 2012 (r244388) M> +++ head/sys/dev/wtap/if_wtap.c Tue Dec 18 08:44:59 2012 (r244389) M> @@ -334,6 +334,10 @@ wtap_vap_create(struct ieee80211com *ic, M> vap = (struct ieee80211vap *) avp; M> error = ieee80211_vap_setup(ic, vap, name, unit, IEEE80211_M_MBSS, M> flags | IEEE80211_CLONE_NOBEACONS, bssid, mac); M> + if (error) { M> + free((struct wtap_vap*) vap, M_80211_VAP); M> + return NULL; M> + } M> M> /* override various methods */ M> avp->av_recv_mgmt = vap->iv_recv_mgmt; You don't need to cast first argument of free(9). And you don't need a cast before malloc(9) as well. If you are calling malloc(9) with M_NOWAIT, you need to check return result. Also, more stylish would be to supply to free() the same variable that was assigned at malloc(9) call, in this particular case it is "avp". Patch attached. -- Totus tuus, Glebius. --UlVJffcvxoiEqYs2 Content-Type: text/x-diff; charset=koi8-r Content-Disposition: attachment; filename="if_wtap.c.diff" Index: if_wtap.c =================================================================== --- if_wtap.c (revision 244389) +++ if_wtap.c (working copy) @@ -326,8 +326,9 @@ DWTAP_PRINTF("%s\n", __func__); - avp = (struct wtap_vap *) malloc(sizeof(struct wtap_vap), - M_80211_VAP, M_NOWAIT | M_ZERO); + avp = malloc(sizeof(struct wtap_vap), M_80211_VAP, M_NOWAIT | M_ZERO); + if (avp == NULL) + return (NULL); avp->id = sc->id; avp->av_md = sc->sc_md; avp->av_bcinterval = msecs_to_ticks(BEACON_INTRERVAL + 100*sc->id); @@ -335,8 +336,8 @@ error = ieee80211_vap_setup(ic, vap, name, unit, IEEE80211_M_MBSS, flags | IEEE80211_CLONE_NOBEACONS, bssid, mac); if (error) { - free((struct wtap_vap*) vap, M_80211_VAP); - return NULL; + free(avp, M_80211_VAP); + return (NULL); } /* override various methods */ --UlVJffcvxoiEqYs2--