diff mbox

[v2] net/flow: Fix potential memory leak

Message ID CA+v9cxZMwTPXw-_pWc-SRsTs5GqmqK2-46Mr06HxhVN4aH93Yg@mail.gmail.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

huajun li Sept. 27, 2011, 10:34 a.m. UTC
While preparing net flow caches, once fail may cause potential memory
leak , fix it.

Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Huajun Li <huajun.li.lee@gmail.com>
---
 net/core/flow.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

Comments

Eric Dumazet Sept. 27, 2011, 12:11 p.m. UTC | #1
Le mardi 27 septembre 2011 à 18:34 +0800, Huajun Li a écrit :
> While preparing net flow caches, once fail may cause potential memory
> leak , fix it.
> 
> Acked-by: Eric Dumazet <eric.dumazet@gmail.com>


Hmm, please dont add "Acked-by" yourself, when submitting a new patch
version. Let us review the new version and ACK it eventually.

> Signed-off-by: Huajun Li <huajun.li.lee@gmail.com>
> ---
>  net/core/flow.c |   16 +++++++++++++++-
>  1 files changed, 15 insertions(+), 1 deletions(-)
> 
> diff --git a/net/core/flow.c b/net/core/flow.c
> index 555a456..4e60fce 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,20 @@ 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;
> +	}
> +
> +	if (fc->percpu) {

test not needed here, fc->percpu is not NULL


> +		free_percpu(fc->percpu);
> +		fc->percpu = NULL;
> +	}
> +
> +	return -ENOMEM;
>  }
> 
>  static int __init flow_cache_init_global(void)


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/core/flow.c b/net/core/flow.c
index 555a456..4e60fce 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,20 @@  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;
+	}
+
+	if (fc->percpu) {
+		free_percpu(fc->percpu);
+		fc->percpu = NULL;
+	}
+
+	return -ENOMEM;
 }

 static int __init flow_cache_init_global(void)