Skip to content

Commit

Permalink
net_sched: fix a resource leak in tcindex_set_parms()
Browse files Browse the repository at this point in the history
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: b9a24bb ("net_sched: properly handle failure case of tcf_exts_init()")
Reported-by: Jakub Kicinski <[email protected]>
Cc: Jamal Hadi Salim <[email protected]>
Cc: Jiri Pirko <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
congwang authored and davem330 committed Feb 5, 2020
1 parent 2c22c06 commit 52b5ae5
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions net/sched/cls_tcindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,

err = tcindex_filter_result_init(&new_filter_result, net);
if (err < 0)
goto errout1;
goto errout_alloc;
if (old_r)
cr = r->res;

Expand Down Expand Up @@ -484,7 +484,6 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
tcindex_free_perfect_hash(cp);
else if (balloc == 2)
kfree(cp->h);
errout1:
tcf_exts_destroy(&new_filter_result.exts);
errout:
kfree(cp);
Expand Down

0 comments on commit 52b5ae5

Please sign in to comment.