Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1427790AbdDWH3k (ORCPT ); Sun, 23 Apr 2017 03:29:40 -0400 Received: from m50-138.163.com ([123.125.50.138]:51182 "EHLO m50-138.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1044270AbdDWH3e (ORCPT ); Sun, 23 Apr 2017 03:29:34 -0400 From: Pan Bian To: Jiri Pirko Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/2] team: fix memory leak Date: Sun, 23 Apr 2017 15:29:24 +0800 Message-Id: <1492932564-722-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: C9GowADXaHDWV_xYTCgdAA--.260S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrZr4DZw1rArW8JFWkAry8AFb_yoWfCwbEgF yS9rs7Xw1Fyrn7K34Fkr4xAryxtF43Z3Z3WryI934ftr9IyrsrJ3Z7Zr1DA397Kr47Ca9x C34DXa45Z34xtjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUUNtxJUUUUU== X-Originating-IP: [123.118.194.153] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiDhnCclXljDrjgQAAsD Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 890 Lines: 29 In function team_nl_send_port_list_get(), pointer skb keeps the return value of nlmsg_new(). When the call to genlmsg_put() fails, the memory is not freed. 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 f8c81f1..dd3a2e9 100644 --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c @@ -2634,8 +2634,10 @@ static int team_nl_send_port_list_get(struct team *team, u32 portid, u32 seq, hdr = genlmsg_put(skb, portid, seq, &team_nl_family, flags | NLM_F_MULTI, TEAM_CMD_PORT_LIST_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