Fix type free memleak
[babeltrace.git] / types / float.c
CommitLineData
0a46062b
MD
1/*
2 * BabelTrace - Float Type Converter
3 *
4 * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <babeltrace/compiler.h>
448d3cc7 22#include <babeltrace/types.h>
0a46062b
MD
23
24size_t float_copy(unsigned char *dest, const struct format *fdest,
25 const unsigned char *src, const struct format *fsrc,
26 const struct type_class *type_class)
27{
28 struct type_class_float *float_class =
29 container_of(type_class, struct type_class_float, p);
30
31 if (fsrc->float_copy == fdest->float_copy) {
32 fsrc->float_copy(dest, float_class, src, float_class);
33 return float_class->mantissa_len + float_class->exp_len;
34 } else {
35 double v;
36
37 v = fsrc->double_read(src, fsrc);
38 return fdest->double_write(dest, fdest, v);
39 }
40}
41
90b676d7
MD
42void float_type_free(struct type_class_float *float_class)
43{
44 g_free(float_class);
45}
46
47static void _float_type_free(struct type_class *type_class)
48{
49 struct type_class_float *float_class =
50 container_of(type_class, struct type_class_float, p);
51 float_type_free(float_class);
52}
53
0a46062b
MD
54struct type_class_float *float_type_new(const char *name,
55 size_t mantissa_len,
56 size_t exp_len, int byte_order,
57 size_t alignment)
58{
59 struct type_class_float *float_class;
60 int ret;
61
0a46062b
MD
62 float_class = g_new(struct type_class_float, 1);
63 float_class->p.name = g_quark_from_string(name);
64 float_class->p.alignment = alignment;
90b676d7
MD
65 float_class->p.copy = float_copy;
66 float_class->p.free = _float_type_free;
0a46062b
MD
67 float_class->mantissa_len = mantissa_len;
68 float_class->exp_len = exp_len;
69 float_class->byte_order = byte_order;
70 if (float_class->p.name) {
71 ret = ctf_register_type(&float_class->p);
72 if (ret) {
73 g_free(float_class);
74 return NULL;
75 }
76 }
77 return float_class;
78}
This page took 0.02514 seconds and 4 git commands to generate.