Re: [Libvir] [patch 2/5] iptables: use calloc() instead of malloc()/memset()

On Wed, Mar 21, 2007 at 12:47:59PM +0000, Mark McLoughlin wrote:
Replace a few instances of malloc() followed by memset(0) with calloc()
Humpf, that's just the opposite of the other parts of libvirt I wrote. Could you justify ? It's hard to catch it's a calloc or a malloc call, and hence notice if it was initialized or not. The extra memset line makes it clear, plus it will allow me more easilly to plug in libxml2 memory wrapper. I doubt the patch is related to other parts needed for the restart code it's just coding policy and IMHO different from teh rest of libvirt. Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

On Wed, 2007-03-21 at 09:07 -0400, Daniel Veillard wrote:
On Wed, Mar 21, 2007 at 12:47:59PM +0000, Mark McLoughlin wrote:
Replace a few instances of malloc() followed by memset(0) with calloc()
Humpf, that's just the opposite of the other parts of libvirt I wrote.
It's more consistent with the rest of libvirt_qemud, though :-)
Could you justify ? It's hard to catch it's a calloc or a malloc call, and hence notice if it was initialized or not.
I'm of two minds, really. Previously I would have always done malloc()/memset() but when using glib I'd tend to use g_new0(). So, it's handy to have a zeroing allocator. I guess I never previously relied on calloc() zeroing the memory since that behaviour isn't reflected in its name.
The extra memset line makes it clear, plus it will allow me more easilly to plug in libxml2 memory wrapper.
Again, wondering why you'd want to use libxml2's wrapper. Cheers, Mark.
participants (2)
-
Daniel Veillard
-
Mark McLoughlin