Fix type free memleak
[babeltrace.git] / types / float.c
index ac1525595bc99c82a95f9cd2bc62321c6480be54..e42daa162170c39d388caba940178da3e4ea14db 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include <babeltrace/compiler.h>
+#include <babeltrace/types.h>
 
 size_t float_copy(unsigned char *dest, const struct format *fdest, 
                  const unsigned char *src, const struct format *fsrc,
@@ -38,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,
@@ -46,12 +59,11 @@ struct type_class_float *float_type_new(const char *name,
        struct type_class_float *float_class;
        int ret;
 
-       /*
-        * Freed when type is unregistered.
-        */
        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;
@@ -64,9 +76,3 @@ struct type_class_float *float_type_new(const char *name,
        }
        return float_class;
 }
-
-void float_type_free(struct type_class_float *float_class)
-{
-       if (!float_class->name)
-               g_free(float_class);
-}
This page took 0.023284 seconds and 4 git commands to generate.