From 0d1a681e2c2521edea85e8748c7be35a60c73155 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 20 May 2011 19:40:09 -0400 Subject: [PATCH] lttng kprobes/ftrace integration: fix memleak Signed-off-by: Mathieu Desnoyers --- ltt-events.h | 8 +++++++- probes/lttng-ftrace.c | 7 +++++++ probes/lttng-kprobes.c | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ltt-events.h b/ltt-events.h index 1419fb67..45d459d4 100644 --- a/ltt-events.h +++ b/ltt-events.h @@ -112,10 +112,16 @@ struct lttng_event_field { struct lttng_type type; }; -struct lttng_event_desc { +struct lttng_event_ctx { const struct lttng_event_field *fields; + unsigned int nr_fields; +}; + +struct lttng_event_desc { const char *name; void *probe_callback; + const struct lttng_event_ctx *ctx; /* context */ + const struct lttng_event_field *fields; /* event payload */ unsigned int nr_fields; }; diff --git a/probes/lttng-ftrace.c b/probes/lttng-ftrace.c index 27f4e2be..061da25a 100644 --- a/probes/lttng-ftrace.c +++ b/probes/lttng-ftrace.c @@ -70,6 +70,10 @@ int lttng_create_ftrace_event(const char *name, struct ltt_event *event) desc->nr_fields = 2; desc->fields = fields = kzalloc(2 * sizeof(struct lttng_event_field), GFP_KERNEL); + if (!desc->fields) { + ret = -ENOMEM; + goto error_fields; + } fields[0].name = "ip"; fields[0].type.atype = atype_integer; fields[0].type.u.basic.integer.size = sizeof(unsigned long); @@ -92,6 +96,8 @@ int lttng_create_ftrace_event(const char *name, struct ltt_event *event) return 0; +error_fields: + kfree(desc->name); error_str: kfree(desc); return ret; @@ -140,6 +146,7 @@ void lttng_ftrace_unregister(struct ltt_event *event) wrapper_unregister_ftrace_function_probe(event->u.ftrace.symbol_name, <tng_ftrace_ops, event); kfree(event->u.ftrace.symbol_name); + kfree(desc->fields); kfree(event->desc->name); kfree(event->desc); } diff --git a/probes/lttng-kprobes.c b/probes/lttng-kprobes.c index daef3600..96e7509c 100644 --- a/probes/lttng-kprobes.c +++ b/probes/lttng-kprobes.c @@ -59,6 +59,10 @@ int lttng_create_kprobe_event(const char *name, struct ltt_event *event) desc->nr_fields = 1; desc->fields = field = kzalloc(1 * sizeof(struct lttng_event_field), GFP_KERNEL); + if (!field) { + ret = -ENOMEM; + goto error_field; + } field->name = "ip"; field->type.atype = atype_integer; field->type.u.basic.integer.size = sizeof(unsigned long); @@ -71,6 +75,8 @@ int lttng_create_kprobe_event(const char *name, struct ltt_event *event) return 0; +error_field: + kfree(desc->name); error_str: kfree(desc); return ret; @@ -118,6 +124,7 @@ int lttng_kprobes_register(const char *name, register_error: kfree(event->u.kprobe.symbol_name); name_error: + kfree(event->desc->fields); kfree(event->desc->name); kfree(event->desc); error: @@ -129,6 +136,7 @@ void lttng_kprobes_unregister(struct ltt_event *event) { unregister_kprobe(&event->u.kprobe.kp); kfree(event->u.kprobe.symbol_name); + kfree(event->desc->fields); kfree(event->desc->name); kfree(event->desc); } -- 2.34.1