From: huajun li Date: Tue, 27 Sep 2011 22:51:39 +0000 (+0000) Subject: net/flow: Fix potential memory leak X-Git-Tag: MMI-PSA29.97-13-9~18247^2~99 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6ccc3abdc97e07e6895323fdab89f84e58b40ece;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git 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 Signed-off-by: David S. Miller --- 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) for_each_online_cpu(i) { if (flow_cache_cpu_prepare(fc, i)) - return -ENOMEM; + goto err; } fc->hotcpu_notifier = (struct notifier_block){ .notifier_call = flow_cache_cpu, @@ -426,6 +426,18 @@ static int __init flow_cache_init(struct flow_cache *fc) add_timer(&fc->rnd_timer); return 0; + +err: + for_each_possible_cpu(i) { + struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, i); + kfree(fcp->hash_table); + fcp->hash_table = NULL; + } + + free_percpu(fc->percpu); + fc->percpu = NULL; + + return -ENOMEM; } static int __init flow_cache_init_global(void)