1 /*
2 * alloc.c - Auxiliary functions for allocating and freeing data structures
3 *
4 * Copyright (C) 2001,2002,2003,2004,2005,2007 Brailcom, o.p.s.
5 *
6 * This is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This software 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 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "alloc.h"
25
spd_fdset_copy(TFDSetElement * old)26 TFDSetElement spd_fdset_copy(TFDSetElement *old)
27 {
28 TFDSetElement new;
29
30 new = *old;
31 new.msg_settings.voice.language =
32 g_strdup(old->msg_settings.voice.language);
33 new.msg_settings.voice.name = g_strdup(old->msg_settings.voice.name);
34 new.client_name = g_strdup(old->client_name);
35 new.output_module = g_strdup(old->output_module);
36 new.index_mark = g_strdup(old->index_mark);
37 new.audio_output_method = g_strdup(old->audio_output_method);
38 new.audio_oss_device = g_strdup(old->audio_oss_device);
39 new.audio_alsa_device = g_strdup(old->audio_alsa_device);
40 new.audio_nas_server = g_strdup(old->audio_nas_server);
41 new.audio_pulse_server = g_strdup(old->audio_pulse_server);
42 new.audio_pulse_device = g_strdup(old->audio_pulse_device);
43
44 return new;
45
46 }
47
spd_message_copy(TSpeechDMessage * old)48 TSpeechDMessage *spd_message_copy(TSpeechDMessage * old)
49 {
50 TSpeechDMessage *new = NULL;
51
52 if (old == NULL)
53 return NULL;
54
55 new = (TSpeechDMessage *) g_malloc(sizeof(TSpeechDMessage));
56
57 *new = *old;
58 new->buf = g_malloc((old->bytes + 1) * sizeof(char));
59 memcpy(new->buf, old->buf, old->bytes);
60 new->buf[new->bytes] = 0;
61 new->settings = spd_fdset_copy(&old->settings);
62
63 return new;
64 }
65
mem_free_fdset(TFDSetElement * fdset)66 void mem_free_fdset(TFDSetElement * fdset)
67 {
68 /* Don't forget that only these items are filled in
69 in a TSpeechDMessage */
70 g_free(fdset->client_name);
71 g_free(fdset->msg_settings.voice.language);
72 g_free(fdset->msg_settings.voice.name);
73 g_free(fdset->output_module);
74 g_free(fdset->index_mark);
75 g_free(fdset->audio_output_method);
76 g_free(fdset->audio_oss_device);
77 g_free(fdset->audio_alsa_device);
78 g_free(fdset->audio_nas_server);
79 g_free(fdset->audio_pulse_server);
80 g_free(fdset->audio_pulse_device);
81 }
82
mem_free_message(TSpeechDMessage * msg)83 void mem_free_message(TSpeechDMessage * msg)
84 {
85 if (msg == NULL)
86 return;
87 g_free(msg->buf);
88 mem_free_fdset(&(msg->settings));
89 g_free(msg);
90 }
91