diff options
author | huajun li <huajun.li.lee@gmail.com> | 2011-09-27 18:51:39 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-10-17 19:18:42 -0400 |
commit | 6ccc3abdc97e07e6895323fdab89f84e58b40ece (patch) | |
tree | f67e421a3bfe38fe616ad5267acd7c28f3657db9 | |
parent | e6f8aa9b90dbb9dbe56e493b91132ced26eaaf81 (diff) |
net/flow: Fix potential memory leak
While preparing net flow caches, once a fail may cause potential
memory leak , fix it.
Signed-off-by: Huajun Li <huajun.li.lee@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/core/flow.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/net/core/flow.c b/net/core/flow.c index 555a456efb07..8ae42de9c79e 100644 --- a/net/core/flow.c +++ b/net/core/flow.c | |||
@@ -413,7 +413,7 @@ static int __init flow_cache_init(struct flow_cache *fc) | |||
413 | 413 | ||
414 | for_each_online_cpu(i) { | 414 | for_each_online_cpu(i) { |
415 | if (flow_cache_cpu_prepare(fc, i)) | 415 | if (flow_cache_cpu_prepare(fc, i)) |
416 | return -ENOMEM; | 416 | goto err; |
417 | } | 417 | } |
418 | fc->hotcpu_notifier = (struct notifier_block){ | 418 | fc->hotcpu_notifier = (struct notifier_block){ |
419 | .notifier_call = flow_cache_cpu, | 419 | .notifier_call = flow_cache_cpu, |
@@ -426,6 +426,18 @@ static int __init flow_cache_init(struct flow_cache *fc) | |||
426 | add_timer(&fc->rnd_timer); | 426 | add_timer(&fc->rnd_timer); |
427 | 427 | ||
428 | return 0; | 428 | return 0; |
429 | |||
430 | err: | ||
431 | for_each_possible_cpu(i) { | ||
432 | struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, i); | ||
433 | kfree(fcp->hash_table); | ||
434 | fcp->hash_table = NULL; | ||
435 | } | ||
436 | |||
437 | free_percpu(fc->percpu); | ||
438 | fc->percpu = NULL; | ||
439 | |||
440 | return -ENOMEM; | ||
429 | } | 441 | } |
430 | 442 | ||
431 | static int __init flow_cache_init_global(void) | 443 | static int __init flow_cache_init_global(void) |