Fix type free memleak
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 30 Sep 2010 20:21:01 +0000 (16:21 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 30 Sep 2010 20:21:01 +0000 (16:21 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/babeltrace/types.h
types/bitfield.c
types/enum.c
types/float.c
types/integer.c
types/types.c

index 3dea99e54b012d7fffc68640af8705f28249b1b8..417bb691ca6020453905c7ecac64596955d00759 100644 (file)
@@ -35,6 +35,7 @@ struct type_class {
        size_t (*copy)(unsigned char *dest, const struct format *fdest, 
                       const unsigned char *src, const struct format *fsrc,
                       const struct type_class *type_class);
        size_t (*copy)(unsigned char *dest, const struct format *fdest, 
                       const unsigned char *src, const struct format *fsrc,
                       const struct type_class *type_class);
+       void (*free)(struct type_class *type_class);
 };
 
 struct type_class_integer {
 };
 
 struct type_class_integer {
index 03d3bbcbafd31aca219ea988289b3f6e6f84517c..a7111b1c454f81a293e4a1dc1244bdd7e0db814a 100644 (file)
@@ -74,6 +74,18 @@ size_t bitfield_copy(unsigned char *dest, const struct format *fdest,
        }
 }
 
        }
 }
 
+void bitfield_type_free(struct type_class_bitfield *bitfield_class)
+{
+       g_free(bitfield_class);
+}
+
+static void _bitfield_type_free(struct type_class *type_class)
+{
+       struct type_class_bitfield *bitfield_class =
+               container_of(type_class, struct type_class_bitfield, p);
+       bitfield_type_free(bitfield_class);
+}
+
 struct type_class_bitfield *bitfield_type_new(const char *name,
                                              size_t start_offset,
                                              size_t len, int byte_order,
 struct type_class_bitfield *bitfield_type_new(const char *name,
                                              size_t start_offset,
                                              size_t len, int byte_order,
@@ -88,6 +100,8 @@ struct type_class_bitfield *bitfield_type_new(const char *name,
        int_class = &bitfield_class->p;
        int_class->p.name = g_quark_from_string(name);
        int_class->p.alignment = alignment;
        int_class = &bitfield_class->p;
        int_class->p.name = g_quark_from_string(name);
        int_class->p.alignment = alignment;
+       int_class->p.copy = bitfield_copy;
+       int_class->p.free = _bitfield_type_free;
        int_class->len = len;
        int_class->byte_order = byte_order;
        int_class->signedness = signedness;
        int_class->len = len;
        int_class->byte_order = byte_order;
        int_class->signedness = signedness;
@@ -101,8 +115,3 @@ struct type_class_bitfield *bitfield_type_new(const char *name,
        }
        return bitfield_class;
 }
        }
        return bitfield_class;
 }
-
-void bitfield_type_free(struct type_class_bitfield *bitfield_class)
-{
-       g_free(bitfield_class);
-}
index 21af948bca20b1c26c8fb51133491e25a6425eb9..0fbc19187ef9e487914fd7540e07e7346fbf8145 100644 (file)
@@ -180,6 +180,21 @@ size_t enum_copy(unsigned char *dest, const struct format *fdest,
        return fdest->enum_write(dest, enum_class, v);
 }
 
        return fdest->enum_write(dest, enum_class, v);
 }
 
+void enum_type_free(struct type_class_enum *enum_class)
+{
+       g_hash_table_destroy(enum_class->table.value_to_quark);
+       g_hash_table_destroy(enum_class->table.quark_to_value);
+       g_free(enum_class);
+}
+
+static
+void _enum_type_free(struct type_class *type_class)
+{
+       struct type_class_enum *enum_class =
+               container_of(type_class, struct type_class_enum, p);
+       enum_type_free(enum_class);
+}
+
 struct type_class_enum *enum_type_new(const char *name,
                                      size_t start_offset,
                                      size_t len, int byte_order,
 struct type_class_enum *enum_type_new(const char *name,
                                      size_t start_offset,
                                      size_t len, int byte_order,
@@ -201,6 +216,8 @@ struct type_class_enum *enum_type_new(const char *name,
        int_class = &bitfield_class->p;
        int_class->p.name = g_quark_from_string(name);
        int_class->p.alignment = alignment;
        int_class = &bitfield_class->p;
        int_class->p.name = g_quark_from_string(name);
        int_class->p.alignment = alignment;
+       int_class->p.copy = enum_copy;
+       int_class->p.free = _enum_type_free;
        int_class->len = len;
        int_class->byte_order = byte_order;
        int_class->signedness = signedness;
        int_class->len = len;
        int_class->byte_order = byte_order;
        int_class->signedness = signedness;
@@ -216,10 +233,3 @@ struct type_class_enum *enum_type_new(const char *name,
        }
        return enum_class;
 }
        }
        return enum_class;
 }
-
-void enum_type_free(struct type_class_enum *enum_class)
-{
-       g_hash_table_destroy(enum_class->table.value_to_quark);
-       g_hash_table_destroy(enum_class->table.quark_to_value);
-       g_free(enum_class);
-}
index 78499c8f14ea6205d732bf3a68b426d0a25221c3..e42daa162170c39d388caba940178da3e4ea14db 100644 (file)
@@ -39,6 +39,18 @@ size_t float_copy(unsigned char *dest, const struct format *fdest,
        }
 }
 
        }
 }
 
+void float_type_free(struct type_class_float *float_class)
+{
+       g_free(float_class);
+}
+
+static void _float_type_free(struct type_class *type_class)
+{
+       struct type_class_float *float_class =
+               container_of(type_class, struct type_class_float, p);
+       float_type_free(float_class);
+}
+
 struct type_class_float *float_type_new(const char *name,
                                        size_t mantissa_len,
                                        size_t exp_len, int byte_order,
 struct type_class_float *float_type_new(const char *name,
                                        size_t mantissa_len,
                                        size_t exp_len, int byte_order,
@@ -50,6 +62,8 @@ struct type_class_float *float_type_new(const char *name,
        float_class = g_new(struct type_class_float, 1);
        float_class->p.name = g_quark_from_string(name);
        float_class->p.alignment = alignment;
        float_class = g_new(struct type_class_float, 1);
        float_class->p.name = g_quark_from_string(name);
        float_class->p.alignment = alignment;
+       float_class->p.copy = float_copy;
+       float_class->p.free = _float_type_free;
        float_class->mantissa_len = mantissa_len;
        float_class->exp_len = exp_len;
        float_class->byte_order = byte_order;
        float_class->mantissa_len = mantissa_len;
        float_class->exp_len = exp_len;
        float_class->byte_order = byte_order;
@@ -62,8 +76,3 @@ struct type_class_float *float_type_new(const char *name,
        }
        return float_class;
 }
        }
        return float_class;
 }
-
-void float_type_free(struct type_class_float *float_class)
-{
-       g_free(float_class);
-}
index cf01f07a70fea8b45d0cdffcce9f45244ebcb5a2..bafb6cb7d1c277f7de321513bfbad08c44ce55a4 100644 (file)
@@ -48,6 +48,18 @@ size_t integer_copy(unsigned char *dest, const struct format *fdest,
        }
 }
 
        }
 }
 
+void integer_type_free(struct type_class_integer *int_class)
+{
+       g_free(int_class);
+}
+
+static void _integer_type_free(struct type_class *type_class)
+{
+       struct type_class_integer *int_class =
+               container_of(type_class, struct type_class_integer, p);
+       integer_type_free(int_class);
+}
+
 struct type_class_integer *integer_type_new(const char *name,
                                            size_t start_offset,
                                            size_t len, int byte_order,
 struct type_class_integer *integer_type_new(const char *name,
                                            size_t start_offset,
                                            size_t len, int byte_order,
@@ -61,6 +73,7 @@ struct type_class_integer *integer_type_new(const char *name,
        int_class->p.name = g_quark_from_string(name);
        int_class->p.alignment = alignment;
        int_class->p.copy = integer_copy;
        int_class->p.name = g_quark_from_string(name);
        int_class->p.alignment = alignment;
        int_class->p.copy = integer_copy;
+       int_class->p.free = _integer_type_free;
        int_class->len = len;
        int_class->byte_order = byte_order;
        int_class->signedness = signedness;
        int_class->len = len;
        int_class->byte_order = byte_order;
        int_class->signedness = signedness;
@@ -73,8 +86,3 @@ struct type_class_integer *integer_type_new(const char *name,
        }
        return int_class;
 }
        }
        return int_class;
 }
-
-void integer_type_free(struct type_class_integer *int_class)
-{
-       g_free(int_class);
-}
index 5c8905517aadee42f95afec1d92df7530fa7ec79..675567f8f1819fcb28beb7c52ff911a54606482d 100644 (file)
@@ -37,6 +37,11 @@ struct type_class *ctf_lookup_type(GQuark qname)
                                   (gconstpointer) (unsigned long) qname)
 }
 
                                   (gconstpointer) (unsigned long) qname)
 }
 
+static void free_type(struct type_class *type_class)
+{
+       type_class->free(type_class);
+}
+
 int ctf_register_type(struct type_class *type_class)
 {
        if (ctf_lookup_type_class(type_class->name))
 int ctf_register_type(struct type_class *type_class)
 {
        if (ctf_lookup_type_class(type_class->name))
@@ -51,7 +56,7 @@ int ctf_register_type(struct type_class *type_class)
 int ctf_init_types(void)
 {
        type_classes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
 int ctf_init_types(void)
 {
        type_classes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
-                                            NULL, g_free);
+                                            NULL, free_type);
        if (!type_classes)
                return -ENOMEM;
        return 0;
        if (!type_classes)
                return -ENOMEM;
        return 0;
This page took 0.039369 seconds and 4 git commands to generate.