提交 3f61cd87 编写于 作者: J Jesper Juhl 提交者: David S. Miller

bnx2x: Fix mem leak in bnx2x_tpa_stop() if build_skb() fails.

We allocate memory for 'new_data' with kmalloc(). If we get the memory
we then try to build_skb() and if that should fail (which it can) we
do not enter 'if (likely(skb)) {' and actually use 'new_data' but
instead fall through to the 'drop:' label and end up returning from
the function without ever assigning 'new'data' to anything or freeing
it. That leaks the memory allocated to 'new_data'.

This patch fixes the memory leak by doing a kfree(new_data) in the
case where build_skb() fails (or where allocation of 'new_data' itself
fails, but in taht case it's just a harmless kfree(NULL)).
Signed-off-by: NJesper Juhl <jj@chaosbits.net>
Acked-by: NEric Dumazet <eric.dumazet@gmail.com>
Acked-by: NEilon Greenstein <eilong@broadcom.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 da091286
...@@ -523,7 +523,6 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp, ...@@ -523,7 +523,6 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
skb = build_skb(data); skb = build_skb(data);
if (likely(skb)) { if (likely(skb)) {
#ifdef BNX2X_STOP_ON_ERROR #ifdef BNX2X_STOP_ON_ERROR
if (pad + len > fp->rx_buf_size) { if (pad + len > fp->rx_buf_size) {
BNX2X_ERR("skb_put is about to fail... " BNX2X_ERR("skb_put is about to fail... "
...@@ -557,7 +556,7 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp, ...@@ -557,7 +556,7 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
return; return;
} }
kfree(new_data);
drop: drop:
/* drop the packet and keep the buffer in the bin */ /* drop the packet and keep the buffer in the bin */
DP(NETIF_MSG_RX_STATUS, DP(NETIF_MSG_RX_STATUS,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册