memory allocation clarification
Chris Brannon
cmbrannon79 at gmail.com
Sat Feb 20 03:09:20 CET 2010
Luke Yelavich <luke.yelavich at canonical.com> wrote:
> On Thu, Feb 18, 2010 at 11:58:35AM EST, jose vilmar estacio de souza wrote:
> > It's important to match |g_malloc()| <http://library.gnome.org/devel/glib/u
> nstable/glib-Memory-Allocation.html#g-malloc>
> > with |g_free()| <http://library.gnome.org/devel/glib/unstable/glib-Memory-A
> llocation.html#g-free>,
*SNIP*
> > Am I missing something?
>
> This sounds correct. I believe one of Chris' recent patches for
> speech-dispatcher corrected such an issue.
Right. g_malloc, g_free, malloc, and free are regularly mixed
in the code. I'll give a couple notable examples.
src/modules/module_utils.c defines a function named module_strip_ssml.
It returns a pointer to memory allocated with libc's malloc.
In src/modules/ibmtts.c, that memory is freed with g_free,
while in src/modules/flite.c, it is freed with libc's free.
src/c/api/libspeechd.c defines a function named
spd_send_data_wo_mutex. This function can return either malloc'ed or
g_malloc'ed data, depending on the condition of an if statement.
Its caller has no way of knowing whether the memory was allocated by libc
or glib.
-- Chris
More information about the Speechd
mailing list