From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KQP2m-0001rN-GA for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:05:52 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KQP2k-0001qj-Kk for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:05:51 -0400 Received: from [199.232.76.173] (port=35053 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KQP2k-0001qZ-EN for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:05:50 -0400 Received: from mx1.redhat.com ([66.187.233.31]:59349) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KQP2j-0006gZ-RM for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:05:50 -0400 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m75G5hLQ013965 for ; Tue, 5 Aug 2008 12:05:43 -0400 Received: from pobox.stuttgart.redhat.com (pobox.stuttgart.redhat.com [172.16.2.10]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m75G5f2U027276 for ; Tue, 5 Aug 2008 12:05:42 -0400 Received: from zweiblum.travel.kraxel.org (vpn-4-71.str.redhat.com [10.32.4.71]) by pobox.stuttgart.redhat.com (8.13.1/8.13.1) with ESMTP id m75G5Zlt016447 for ; Tue, 5 Aug 2008 12:05:35 -0400 Message-ID: <48987A4F.4060708@redhat.com> Date: Tue, 05 Aug 2008 18:05:35 +0200 From: Gerd Hoffmann MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040501010606090808030202" Subject: [Qemu-devel] [PATCH] add qemu_realloc(). Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------040501010606090808030202 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi, This adds qemu_realloc() to the collection of qemu_* allocation functions and switches existing realloc() users to it. please apply, Gerd -- http://kraxel.fedorapeople.org/xenner/ --------------040501010606090808030202 Content-Type: text/plain; name="0003-Add-qemu_realloc-function.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0003-Add-qemu_realloc-function.patch" >>From e946ff30fe1ae9151d7edf074cbf79575528d1ce Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Tue, 5 Aug 2008 10:18:58 +0200 Subject: [PATCH] Add qemu_realloc() function. This patch adds a qemu_realloc() function and switches over the realloc() users to the new qemu_realloc() function. Signed-off-by: Gerd Hoffmann --- block-dmg.c | 10 +++++----- block-vvfat.c | 4 ++-- hw/blizzard.c | 2 +- hw/lsi53c895a.c | 2 +- hw/rtl8139.c | 2 +- hw/soc_dma.c | 6 +++--- qemu-common.h | 1 + qemu-malloc.c | 5 +++++ vnc.c | 6 +++--- 9 files changed, 22 insertions(+), 16 deletions(-) diff --git a/block-dmg.c b/block-dmg.c index 62117c9..8c9d0da 100644 --- a/block-dmg.c +++ b/block-dmg.c @@ -125,11 +125,11 @@ dmg_close: goto dmg_close; chunk_count = (count-204)/40; new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count); - s->types = realloc(s->types, new_size/2); - s->offsets = realloc(s->offsets, new_size); - s->lengths = realloc(s->lengths, new_size); - s->sectors = realloc(s->sectors, new_size); - s->sectorcounts = realloc(s->sectorcounts, new_size); + s->types = qemu_realloc(s->types, new_size/2); + s->offsets = qemu_realloc(s->offsets, new_size); + s->lengths = qemu_realloc(s->lengths, new_size); + s->sectors = qemu_realloc(s->sectors, new_size); + s->sectorcounts = qemu_realloc(s->sectorcounts, new_size); for(i=s->n_chunks;in_chunks+chunk_count;i++) { s->types[i] = read_uint32(s->fd); diff --git a/block-vvfat.c b/block-vvfat.c index 9394fbd..6de76c6 100644 --- a/block-vvfat.c +++ b/block-vvfat.c @@ -101,7 +101,7 @@ static inline int array_ensure_allocated(array_t* array, int index) { if((index + 1) * array->item_size > array->size) { int new_size = (index + 32) * array->item_size; - array->pointer = realloc(array->pointer, new_size); + array->pointer = qemu_realloc(array->pointer, new_size); if (!array->pointer) return -1; array->size = new_size; @@ -127,7 +127,7 @@ static inline void* array_get_next(array_t* array) { static inline void* array_insert(array_t* array,unsigned int index,unsigned int count) { if((array->next+count)*array->item_size>array->size) { int increment=count*array->item_size; - array->pointer=realloc(array->pointer,array->size+increment); + array->pointer=qemu_realloc(array->pointer,array->size+increment); if(!array->pointer) return 0; array->size+=increment; diff --git a/hw/blizzard.c b/hw/blizzard.c index 37330e7..4fb005e 100644 --- a/hw/blizzard.c +++ b/hw/blizzard.c @@ -192,7 +192,7 @@ static int blizzard_transfer_setup(struct blizzard_s *s) s->data.len = s->bpp * s->data.dx * s->data.dy; s->data.pitch = s->data.dx; if (s->data.len > s->data.buflen) { - s->data.buf = realloc(s->data.buf, s->data.len); + s->data.buf = qemu_realloc(s->data.buf, s->data.len); s->data.buflen = s->data.len; } s->data.ptr = s->data.buf; diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c index a08cfd9..9a212e2 100644 --- a/hw/lsi53c895a.c +++ b/hw/lsi53c895a.c @@ -501,7 +501,7 @@ static void lsi_queue_command(LSIState *s) DPRINTF("Queueing tag=0x%x\n", s->current_tag); if (s->queue_len == s->active_commands) { s->queue_len++; - s->queue = realloc(s->queue, s->queue_len * sizeof(lsi_queue)); + s->queue = qemu_realloc(s->queue, s->queue_len * sizeof(lsi_queue)); } p = &s->queue[s->active_commands++]; p->tag = s->current_tag; diff --git a/hw/rtl8139.c b/hw/rtl8139.c index 0222d42..6aec2ff 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -2001,7 +2001,7 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) while (s->cplus_txbuffer && s->cplus_txbuffer_offset + txsize >= s->cplus_txbuffer_len) { s->cplus_txbuffer_len += CP_TX_BUFFER_SIZE; - s->cplus_txbuffer = realloc(s->cplus_txbuffer, s->cplus_txbuffer_len); + s->cplus_txbuffer = qemu_realloc(s->cplus_txbuffer, s->cplus_txbuffer_len); DEBUG_PRINT(("RTL8139: +++ C+ mode transmission buffer space changed to %d\n", s->cplus_txbuffer_len)); } diff --git a/hw/soc_dma.c b/hw/soc_dma.c index 4ff8cae..4c87c8b 100644 --- a/hw/soc_dma.c +++ b/hw/soc_dma.c @@ -50,7 +50,7 @@ static int fifo_size; void transfer_fifo2fifo(struct soc_dma_ch_s *ch) { if (ch->bytes > fifo_size) - fifo_buf = realloc(fifo_buf, fifo_size = ch->bytes); + fifo_buf = qemu_realloc(fifo_buf, fifo_size = ch->bytes); /* Implement as transfer_fifo2linear + transfer_linear2fifo. */ ch->io_fn[0](ch->io_opaque[0], fifo_buf, ch->bytes); @@ -262,7 +262,7 @@ void soc_dma_port_add_fifo(struct soc_dma_s *soc, target_phys_addr_t virt_base, struct memmap_entry_s *entry; struct dma_s *dma = (struct dma_s *) soc; - dma->memmap = realloc(dma->memmap, sizeof(*entry) * + dma->memmap = qemu_realloc(dma->memmap, sizeof(*entry) * (dma->memmap_size + 1)); entry = soc_dma_lookup(dma, virt_base); @@ -314,7 +314,7 @@ void soc_dma_port_add_mem(struct soc_dma_s *soc, uint8_t *phys_base, struct memmap_entry_s *entry; struct dma_s *dma = (struct dma_s *) soc; - dma->memmap = realloc(dma->memmap, sizeof(*entry) * + dma->memmap = qemu_realloc(dma->memmap, sizeof(*entry) * (dma->memmap_size + 1)); entry = soc_dma_lookup(dma, virt_base); diff --git a/qemu-common.h b/qemu-common.h index b991c2b..23d1444 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -87,6 +87,7 @@ int stristart(const char *str, const char *val, const char **ptr); time_t mktimegm(struct tm *tm); void *qemu_malloc(size_t size); +void *qemu_realloc(void *ptr, size_t size); void *qemu_mallocz(size_t size); void qemu_free(void *ptr); char *qemu_strdup(const char *str); diff --git a/qemu-malloc.c b/qemu-malloc.c index 16d3c2e..606eda6 100644 --- a/qemu-malloc.c +++ b/qemu-malloc.c @@ -38,6 +38,11 @@ void *qemu_malloc(size_t size) return malloc(size); } +void *qemu_realloc(void *ptr, size_t size) +{ + return realloc(ptr, size); +} + void *qemu_mallocz(size_t size) { void *ptr; diff --git a/vnc.c b/vnc.c index 31118ee..2d17044 100644 --- a/vnc.c +++ b/vnc.c @@ -291,8 +291,8 @@ static void vnc_dpy_resize(DisplayState *ds, int w, int h) int size_changed; VncState *vs = ds->opaque; - ds->data = realloc(ds->data, w * h * vs->depth); - vs->old_data = realloc(vs->old_data, w * h * vs->depth); + ds->data = qemu_realloc(ds->data, w * h * vs->depth); + vs->old_data = qemu_realloc(vs->old_data, w * h * vs->depth); if (ds->data == NULL || vs->old_data == NULL) { fprintf(stderr, "vnc: memory allocation failed\n"); @@ -611,7 +611,7 @@ static void buffer_reserve(Buffer *buffer, size_t len) { if ((buffer->capacity - buffer->offset) < len) { buffer->capacity += (len + 1024); - buffer->buffer = realloc(buffer->buffer, buffer->capacity); + buffer->buffer = qemu_realloc(buffer->buffer, buffer->capacity); if (buffer->buffer == NULL) { fprintf(stderr, "vnc: out of memory\n"); exit(1); -- 1.5.5.1 --------------040501010606090808030202--