From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:39553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbUID-0005f0-Lk for qemu-devel@nongnu.org; Fri, 16 Dec 2011 04:41:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RbUI7-0003x7-P0 for qemu-devel@nongnu.org; Fri, 16 Dec 2011 04:41:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56558) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbUI7-0003x2-EE for qemu-devel@nongnu.org; Fri, 16 Dec 2011 04:41:23 -0500 Date: Fri, 16 Dec 2011 09:41:17 +0000 From: "Daniel P. Berrange" Message-ID: <20111216094117.GB9860@redhat.com> References: <4EEB0EC9.6030705@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4EEB0EC9.6030705@redhat.com> Subject: Re: [Qemu-devel] [patch] replace all strdup() with g_strdup() Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel , Jun Koi On Fri, Dec 16, 2011 at 10:26:33AM +0100, Paolo Bonzini wrote: > On 12/16/2011 09:07 AM, Jun Koi wrote: > >This patch replaces all the strdup() with g_strdup() > > > >Signed-off-by: Jun Koi > > > >$ diffstat strdup.diff > > cmd.c | 4 ++-- > > envlist.c | 6 +++--- > > exec.c | 2 +- > > hw/isa-bus.c | 2 +- > > hw/pc.c | 2 +- > > hw/pci.c | 2 +- > > hw/qdev.c | 2 +- > > hw/scsi-bus.c | 2 +- > > hw/sun4m.c | 6 +++--- > > hw/sun4u.c | 2 +- > > hw/usb-msd.c | 2 +- > > hw/virtio-blk.c | 2 +- > > ia64-dis.c | 2 +- > > microblaze-dis.c | 18 +++++++++--------- > > path.c | 2 +- > > readline.c | 2 +- > > test-qmp-commands.c | 12 ++++++------ > > 17 files changed, 35 insertions(+), 35 deletions(-) > > You cannot do this unless you also convert all free to g_free. So > you also cannot do this when you are passing strings to libraries > that take ownership of the strings. A search-and-replace conversion > is not possible. 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. That all said, we probably *do* want to take care todo the matching for any parts of the QEMU codebase which may end up being built into ELF libraries for external consumption. Regards, Daniel. -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|