Fix type free memleak
[babeltrace.git] / types / enum.c
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);
 }
 
+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,
@@ -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->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;
@@ -216,10 +233,3 @@ struct type_class_enum *enum_type_new(const char *name,
        }
        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);
-}
This page took 0.034256 seconds and 4 git commands to generate.