Patchwork [12/15] w32: Make qemu_vfree() accept NULL like the POSIX implementation

login
register
mail settings
Submitter Stefan Hajnoczi
Date Jan. 15, 2013, 4:48 p.m.
Message ID <1358268511-27061-13-git-send-email-stefanha@redhat.com>
Download mbox | patch
Permalink /patch/212253/
State New
Headers show

Comments

Stefan Hajnoczi - Jan. 15, 2013, 4:48 p.m.
From: Markus Armbruster <armbru@redhat.com>

On POSIX, qemu_vfree() accepts NULL, because it's merely wrapper
around free().  As far as I can tell, the Windows implementation
doesn't.  Breeds bugs that bite only under Windows.

Make the Windows implementation behave like the POSIX implementation.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 util/oslib-win32.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch

diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index e7e283e..640194c 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -71,7 +71,9 @@  void *qemu_vmalloc(size_t size)
 void qemu_vfree(void *ptr)
 {
     trace_qemu_vfree(ptr);
-    VirtualFree(ptr, 0, MEM_RELEASE);
+    if (ptr) {
+        VirtualFree(ptr, 0, MEM_RELEASE);
+    }
 }
 
 /* FIXME: add proper locking */