Skip to content

Commit 9a9e774

Browse files
thazhemadamdavem330
authored andcommitted
net: team: fix memory leak in __team_options_register
The variable "i" isn't initialized back correctly after the first loop under the label inst_rollback gets executed. The value of "i" is assigned to be option_count - 1, and the ensuing loop (under alloc_rollback) begins by initializing i--. Thus, the value of i when the loop begins execution will now become i = option_count - 2. Thus, when kfree(dst_opts[i]) is called in the second loop in this order, (i.e., inst_rollback followed by alloc_rollback), dst_optsp[option_count - 2] is the first element freed, and dst_opts[option_count - 1] does not get freed, and thus, a memory leak is caused. This memory leak can be fixed, by assigning i = option_count (instead of option_count - 1). Fixes: 80f7c66 ("team: add support for per-port options") Reported-by: [email protected] Tested-by: [email protected] Signed-off-by: Anant Thazhemadam <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 790ca79 commit 9a9e774

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/net/team/team.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static int __team_options_register(struct team *team,
287287
for (i--; i >= 0; i--)
288288
__team_option_inst_del_option(team, dst_opts[i]);
289289

290-
i = option_count - 1;
290+
i = option_count;
291291
alloc_rollback:
292292
for (i--; i >= 0; i--)
293293
kfree(dst_opts[i]);

0 commit comments

Comments
 (0)