lttng kprobes/ftrace integration: fix memleak
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 20 May 2011 23:40:09 +0000 (19:40 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 20 May 2011 23:40:09 +0000 (19:40 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
ltt-events.h
probes/lttng-ftrace.c
probes/lttng-kprobes.c

index 1419fb67219e047c6125ebf9af4183a7c8bc0a51..45d459d47f39af0187763a38d75e5283652f1987 100644 (file)
@@ -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;
 };
 
index 27f4e2bef81117b6bb1e0dc257b838f1c97162c0..061da25a1475bceda81c48facd6570d27a37bdf1 100644 (file)
@@ -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,
                        &lttng_ftrace_ops, event);
        kfree(event->u.ftrace.symbol_name);
+       kfree(desc->fields);
        kfree(event->desc->name);
        kfree(event->desc);
 }
index daef3600feefd580bb0db79357d09428f8eb21eb..96e7509c328bedb3211e3e3e3dfc4e4d6450f4a8 100644 (file)
@@ -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);
 }
This page took 0.027713 seconds and 4 git commands to generate.