From: Huajun Li <hidden> Date: 2011-09-24 15:57:15
While preparing flow caches, once fail may cause potential memory leak , fix it.
Signed-off-by: Huajun Li <redacted>
---
net/core/flow.c | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
From: Eric Dumazet <hidden> Date: 2011-09-26 06:09:19
Le samedi 24 septembre 2011 à 23:57 +0800, Huajun Li a écrit :
quoted hunk
While preparing flow caches, once fail may cause potential memory leak , fix it.
Signed-off-by: Huajun Li <redacted>
---
net/core/flow.c | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
++ return -ENOMEM; } static int __init flow_cache_init_global(void)
Previous to 2.6.37 (commit 83b6b1f5d134), a memory allocation at this
stage was panicing the box, so no worry about mem leak :)
Now I wonder if a proper patch would not print a nice message in
flow_cache_init_global() if flow_cache_init() returns an error, instead
of silently panicing or something worse...
Before submitting a new patch, could you test this case (injecting a
memalloc error in flow_cache_cpu_prepare() for example.
From: Huajun Li <hidden> Date: 2011-09-26 08:43:10
Eric, thanks for your comment.
2011/9/26 Eric Dumazet [off-list ref]:
Le samedi 24 septembre 2011 à 23:57 +0800, Huajun Li a écrit :
quoted
While preparing flow caches, once fail may cause potential memory leak , fix it.
Signed-off-by: Huajun Li <redacted>
---
net/core/flow.c | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
@@ -433,6 +433,23 @@ static int __init flow_cache_init(struct flow_cache *fc)
add_timer(&fc->rnd_timer);
return 0;
+err:
+ if (fc->percpu) {
+ free_percpu(fc->percpu);
+ fc->percpu = NULL;
+ }
+
+ /*
+ * Check each possible CPUs rather than online ones because they may be
+ * offline before the notifier is registered.
+ */
+
+ return -ENOMEM;
}
static int __init flow_cache_init_global(void)
Previous to 2.6.37 (commit 83b6b1f5d134), a memory allocation at this
stage was panicing the box, so no worry about mem leak :)
Now I wonder if a proper patch would not print a nice message in
flow_cache_init_global() if flow_cache_init() returns an error, instead
of silently panicing or something worse...
There prints err msg in flow_cache_cpu_prepare(L369) if fails to
allocate memory. Do you mean it should give more detail error info,
right ?
Before submitting a new patch, could you test this case (injecting a
memalloc error in flow_cache_cpu_prepare() for example.
From: Huajun Li <hidden> Date: 2011-09-27 09:59:01
2011/9/26 Eric Dumazet [off-list ref]:
Le samedi 24 septembre 2011 à 23:57 +0800, Huajun Li a écrit :
quoted
While preparing flow caches, once fail may cause potential memory leak , fix it.
Signed-off-by: Huajun Li <redacted>
---
net/core/flow.c | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
@@ -433,6 +433,23 @@ static int __init flow_cache_init(struct flow_cache *fc)
add_timer(&fc->rnd_timer);
return 0;
+err:
+ if (fc->percpu) {
+ free_percpu(fc->percpu);
+ fc->percpu = NULL;
+ }
+
+ /*
+ * Check each possible CPUs rather than online ones because they may be
+ * offline before the notifier is registered.
+ */
+
+ return -ENOMEM;
}
static int __init flow_cache_init_global(void)
Previous to 2.6.37 (commit 83b6b1f5d134), a memory allocation at this
stage was panicing the box, so no worry about mem leak :)
To emulate memory allocation fail case, I added code to return
'-ENOMEM' from flow_cache_cpu_prepare(...) even if it could allocate
memory correctly, but did not find panic on my box, maybe the latest
code changed greatly than 2.6.37. :)
From: Eric Dumazet <hidden> Date: 2011-09-27 12:07:26
Le mardi 27 septembre 2011 à 17:58 +0800, Huajun Li a écrit :
To emulate memory allocation fail case, I added code to return
'-ENOMEM' from flow_cache_cpu_prepare(...) even if it could allocate
memory correctly, but did not find panic on my box, maybe the latest
code changed greatly than 2.6.37. :)
To panic the box, you need to leave a NULL pointer somewhere and
dereference it later, when code assumes it cant be NULL ;)