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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]