On 12/16/2011 10:41 AM, Daniel P. Berrange wrote:
Yes& no. In general you are correct that g_malloc/g_strdup needs to
be matched with g_free, but in the context of the QEMU binary at least
we don't strictly need that.
The general issue is that GLib's memory allocators default to the
system malloc/free, but with g_mem_set_vtable it is possible
to override those allocators.
So any libraries using GLib should definitely take care to match
g_malloc/g_strdup/g_free, but if you are a self contained program
that never calls g_mem_set_vtable, we don't technically have to
worry about it.
I think the keyword here is "technically". :) If we want to use the
GLib profiling allocators or any other kind of statistic gathering, we
do have to match the allocations. Right now, we're not getting it 100%
right, but sweeping conversions make it harder to just grep-w for
malloc/free/strdup.
Paolo