Skip to contentSkip to conversation

[6466] Fix qemu_malloc.

Qemu-devel malc 3 participants 4 messages Jan 28, 2009

lore
Share & tools
lore

malc

author
#0 lore raw

Revision: 6466

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6466
Author:   malc
Date:     2009-01-28 17:16:56 +0000 (Wed, 28 Jan 2009)

Log Message:
-----------
Fix qemu_malloc.

make {linux,bsd}-user qemu_realloc handle ptr == NULL correctly. spotted by malc.

Modified Paths:
--------------
trunk/bsd-user/mmap.c
trunk/linux-user/mmap.c

Modified: trunk/bsd-user/mmap.c
===================================================================

bsd-user/mmap.c +2 -0
@@ -127,6 +127,8 @@
     size_t old_size, copy;
     void *new_ptr;
 
+    if (!ptr)
+        return qemu_malloc(size);
     old_size = *(size_t *)((char *)ptr - 16);
     copy = old_size < size ? old_size : size;
     new_ptr = qemu_malloc(size);

Modified: trunk/linux-user/mmap.c
===================================================================

linux-user/mmap.c +2 -0
@@ -128,6 +128,8 @@
     size_t old_size, copy;
     void *new_ptr;
 
+    if (!ptr)
+        return qemu_malloc(size);
     old_size = *(size_t *)((char *)ptr - 16);
     copy = old_size < size ? old_size : size;
     new_ptr = qemu_malloc(size);
#1 lore raw

[Qemu-devel] PATCH: qemu_mallocz(): minus one function and replace calloc() instead malloc()

May be this better?

qemu-malloc.c Locally Modified (Based On LOCAL) renamed from qemu-malloc.c Base (BASE) +1 -2
@@ -46,10 +46,9 @@
 void *(size_t size)
 {
     void *ptr;
-    ptr = qemu_malloc(size);
+    ptr = calloc(1, size);
     if (!ptr)
         return NULL;
-    memset(ptr, 0, size);
     return ptr;
 }
 
#2 lore raw

Re: [Qemu-devel] PATCH: qemu_mallocz(): minus one function and replace calloc() instead malloc()

Quoted 8 lines · Pavel Vasilyev

May be this better?

qemu-malloc.c Locally Modified (Based On LOCAL) renamed from qemu-malloc.c Base (BASE) +0 -0
@@ -46,10 +46,9 @@
 void *(size_t size)

qemu-malloc.c Locally Modified (Based On LOCAL) line 54

Quoted 10 lines
qemu-malloc.c Locally Modified (Based On LOCAL) renamed from qemu-malloc.c Base (BASE) +1 -2
 {
     void *ptr;
-    ptr = qemu_malloc(size);
+    ptr = calloc(1, size);
     if (!ptr)
         return NULL;
-    memset(ptr, 0, size);
     return ptr;
 }
 

This is allocation in system emulation, Malc patch's was about user emulation.

Signature · 3 lines
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris
author
#3 lore raw

Re: [Qemu-devel] PATCH: qemu_mallocz(): minus one function and replace calloc() instead malloc()

Quoted 14 lines · Lionel Landwerlin

Le mercredi 28 janvier 2009 ЪЪ 21:44 +0300, Pavel Vasilyev a ЪЪcrit :

Quoted 13 lines

May be this better?

qemu-malloc.c Locally Modified (Based On LOCAL) renamed from qemu-malloc.c Base (BASE) +1 -1
@@ -46,10 +46,9 @@
 void *(size_t size)
 {
     void *ptr;
-    ptr = qemu_malloc(size);
+    ptr = calloc(1, size);
     if (!ptr)
Quoted 8 lines

qemu-malloc.c Locally Modified (Based On LOCAL) line 54

Quoted 5 lines
qemu-malloc.c Locally Modified (Based On LOCAL) renamed from qemu-malloc.c Base (BASE) +0 -1
         return NULL;
-    memset(ptr, 0, size);
     return ptr;
 }
 

This is allocation in system emulation, Malc patch's was about user emulation.

It wasn't mine, it was Gerd Hoffmann, but his submission, while fine enough for git, left the SVN commit without proper author attribution (I normally wouldn't have 'spotted by malc' in the commit messages, so
that was a good enough give away, that the patch wasn't mine)

Sorry Gerd, perhaps it's a good idea to add Signed-off-by lines after all, if only to know who wrote what.

Signature · 1 line
mailto:[email protected]