Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1427837AbdDWHaC (ORCPT ); Sun, 23 Apr 2017 03:30:02 -0400 Received: from m50-133.163.com ([123.125.50.133]:58631 "EHLO m50-133.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1427807AbdDWH34 (ORCPT ); Sun, 23 Apr 2017 03:29:56 -0400 From: Pan Bian To: Jiri Pirko Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 2/2] team: fix memory leak Date: Sun, 23 Apr 2017 15:29:43 +0800 Message-Id: <1492932583-770-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DdGowACn4l7oV_xY5xoYAA--.340S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrurWrtFyxurykGFykWw17KFg_yoWftFX_Ww 1Ivrs7Xw1FkrnFk3W0kw4rJFyfKF43Z3WkuryI934fta4YyrnrJw1kZr1DAFZ7Kr4xCFZx GwnrXFyrAryIyjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUUZa9PUUUUU== X-Originating-IP: [123.118.194.153] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiDgzCclXljDrj+wAAss Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 925 Lines: 29 In function team_nl_send_options_get(), pointer skb keeps the return value of function nlmsg_new(). When the call to genlmsg_put() fails, the control flow directly returns and does not free skb. This will result in a memory leak bug. This patch fixes it. Signed-off-by: Pan Bian --- drivers/net/team/team.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c index dd3a2e9..85c0124 100644 --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c @@ -2361,8 +2361,10 @@ static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq, hdr = genlmsg_put(skb, portid, seq, &team_nl_family, flags | NLM_F_MULTI, TEAM_CMD_OPTIONS_GET); - if (!hdr) + if (!hdr) { + nlmsg_free(skb); return -EMSGSIZE; + } if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex)) goto nla_put_failure; -- 1.9.1