[libvirt] PATCH: Fix virRealloc for zero-sized alloc

The change to use arrays instead of linked-lists exposed a tiny bug in the virReallocN function. The realloc() contract says that if size is zero, then its semantics are the same as free(). virReallocN wasn't matching this, instead returning failure, and not setting the original pointer to NULL as expected. I've just committed this patch to fix this bug which was causing test suite crashes $ cvs -q diff -up memory.c Index: memory.c =================================================================== RCS file: /data/cvs/libvirt/src/memory.c,v retrieving revision 1.8 diff -u -p -r1.8 memory.c --- memory.c 19 Jun 2008 11:58:49 -0000 1.8 +++ memory.c 10 Oct 2008 18:16:43 -0000 @@ -158,7 +158,7 @@ int __virReallocN(void *ptrptr, size_t s return -1; } tmp = realloc(*(void**)ptrptr, size * count); - if (!tmp) + if (!tmp && (size * count)) return -1; *(void**)ptrptr = tmp; return 0; Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Fri, Oct 10, 2008 at 07:18:44PM +0100, Daniel P. Berrange wrote:
The change to use arrays instead of linked-lists exposed a tiny bug in the virReallocN function. The realloc() contract says that if size is zero, then its semantics are the same as free(). virReallocN wasn't matching this, instead returning failure, and not setting the original pointer to NULL as expected. I've just committed this patch to fix this bug which was causing test suite crashes
yup looks just fine ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (2)
-
Daniel P. Berrange
-
Daniel Veillard