[Libvirt-cim] [PATCH] Make inst_list_free() handle NULL pointers

Dan Smith danms at us.ibm.com
Fri Jan 11 15:28:31 UTC 2008


HE>  void inst_list_free(struct inst_list *list)
HE>  {
HE> +        if (!list)
HE> +                return;
HE> +        
HE>          free(list->list);
HE>          inst_list_init(list);
HE>  }

I have no problem with this patch, although I'd like to reiterate that
it won't solve the initialization problem.

If you have this:

  struct inst_list foo;

  inst_list_free(&foo);

You're passing in the address of a stack variable, which will never be
NULL, so the additional check will fall through.  The free() will then
attempt to free a garbage pointer (list is valid, but list->list is
not) and the heap is blown.

I'd also point out that we overwhelmingly use inst_list variables on
the stack, which means 99% of the time, this check won't help us, and
will just consume "extra cycles".  I'm sure that this would eclipse
the overhead of a few unnecessary inst_list_init() calls :)

I'm fine applying this to handle the case where we might have a
dynamically-allocated list pointer.  Any objections?

-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: danms at us.ibm.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvirt-cim/attachments/20080111/1bdb60fa/attachment.sig>


More information about the Libvirt-cim mailing list