[PATCH] hw breakpoints: Fix possible memory leak

From: Namhyung Kim
Date: Sun Feb 26 2012 - 22:02:19 EST


If kzalloc() for TYPE_DATA failed on a given cpu, previous chunk
will be leaked. Fix it.

Signed-off-by: Namhyung Kim <namhyung.kim@xxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxxxxxxxxxx>
Link: http://lkml.kernel.org/r/1330311739-24302-1-git-send-email-namhyung.kim@xxxxxxx
[ rearranged the code to have a clearer flow ]
Signed-off-by: Ingo Molnar <mingo@xxxxxxx>
---
kernel/events/hw_breakpoint.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index b7971d6..867032d 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -636,10 +636,9 @@ int __init init_hw_breakpoint(void)
for_each_possible_cpu(cpu) {
for (i = 0; i < TYPE_MAX; i++) {
task_bp_pinned = &per_cpu(nr_task_bp_pinned[i], cpu);
- *task_bp_pinned = kzalloc(sizeof(int) * nr_slots[i],
- GFP_KERNEL);
+ *task_bp_pinned = kzalloc(sizeof(int) * nr_slots[i], GFP_KERNEL);
if (!*task_bp_pinned)
- goto err_alloc;
+ goto err_alloc_pinned;
}
}

@@ -649,6 +648,9 @@ int __init init_hw_breakpoint(void)

return register_die_notifier(&hw_breakpoint_exceptions_nb);

+ err_alloc_pinned:
+ while (--i >= 0)
+ kfree(per_cpu(nr_task_bp_pinned[i], cpu));
err_alloc:
for_each_possible_cpu(err_cpu) {
if (err_cpu == cpu)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/