Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net_sched: fix a resource leak in tcindex_set_parms()

Jakub noticed there is a potential resource leak in
tcindex_set_parms(): when tcindex_filter_result_init() fails
and it jumps to 'errout1' which doesn't release the memory
and resources allocated by tcindex_alloc_perfect_hash().

We should just jump to 'errout_alloc' which calls
tcindex_free_perfect_hash().

Fixes: b9a24bb76bf6 ("net_sched: properly handle failure case of tcf_exts_init()")
Reported-by: Jakub Kicinski <kuba@kernel.org>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Cong Wang and committed by
David S. Miller
52b5ae50 2c22c06c

+1 -2
+1 -2
net/sched/cls_tcindex.c
··· 365 365 366 366 err = tcindex_filter_result_init(&new_filter_result, net); 367 367 if (err < 0) 368 - goto errout1; 368 + goto errout_alloc; 369 369 if (old_r) 370 370 cr = r->res; 371 371 ··· 484 484 tcindex_free_perfect_hash(cp); 485 485 else if (balloc == 2) 486 486 kfree(cp->h); 487 - errout1: 488 487 tcf_exts_destroy(&new_filter_result.exts); 489 488 errout: 490 489 kfree(cp);