On Wed, Mar 21, 2007 at 12:47:58PM +0000, Mark McLoughlin wrote: > In iptablesContextNew(), make sure we don't try and free an invalid > pointer if one of the iptRulesNew() fails. > > Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx> > > Index: libvirt/qemud/iptables.c > =================================================================== > --- libvirt.orig/qemud/iptables.c > +++ libvirt/qemud/iptables.c > @@ -496,7 +496,7 @@ iptablesContextNew(void) > { > iptablesContext *ctx; > > - if (!(ctx = (iptablesContext *) malloc(sizeof (iptablesContext)))) > + if (!(ctx = (iptablesContext *) calloc(1, sizeof (iptablesContext)))) > return NULL; > > if (!(ctx->input_filter = iptRulesNew("filter", IPTABLES_PREFIX "INPUT"))) I usually prefer malloc + memset( , 0, ) , but this probably comes from libxml2 where I replaced malloc calls with specific wrappers (and I still have a TODO for this in libvirt though some part of libvirt are not linked to libxml2 I guess so that may make things a bit harder) What's the policy w.r.t. error reporting in qemud and libvirt related daemons in general ? I guess a failure to malloc or thisd kind of problems should be logged somewhere, right ? > @@ -518,9 +518,12 @@ iptablesContextNew(void) > void > iptablesContextFree(iptablesContext *ctx) > { > - iptRulesFree(ctx->input_filter); > - iptRulesFree(ctx->forward_filter); > - iptRulesFree(ctx->nat_postrouting); > + if (ctx->input_filter) > + iptRulesFree(ctx->input_filter); > + if (ctx->forward_filter) > + iptRulesFree(ctx->forward_filter); > + if (ctx->nat_postrouting) > + iptRulesFree(ctx->nat_postrouting); > free(ctx); > } The patch does the right thing, sounds good to me :-) Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@xxxxxxxxxx | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/