Commit 2137b4cca9af2ca22b527ef9f3835c532511453d
1 parent
bf6bca52
Add qemu_realloc(), by Gerd Hoffmann.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4986 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
9 changed files
with
22 additions
and
16 deletions
block-dmg.c
... | ... | @@ -125,11 +125,11 @@ dmg_close: |
125 | 125 | goto dmg_close; |
126 | 126 | chunk_count = (count-204)/40; |
127 | 127 | new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count); |
128 | - s->types = realloc(s->types, new_size/2); | |
129 | - s->offsets = realloc(s->offsets, new_size); | |
130 | - s->lengths = realloc(s->lengths, new_size); | |
131 | - s->sectors = realloc(s->sectors, new_size); | |
132 | - s->sectorcounts = realloc(s->sectorcounts, new_size); | |
128 | + s->types = qemu_realloc(s->types, new_size/2); | |
129 | + s->offsets = qemu_realloc(s->offsets, new_size); | |
130 | + s->lengths = qemu_realloc(s->lengths, new_size); | |
131 | + s->sectors = qemu_realloc(s->sectors, new_size); | |
132 | + s->sectorcounts = qemu_realloc(s->sectorcounts, new_size); | |
133 | 133 | |
134 | 134 | for(i=s->n_chunks;i<s->n_chunks+chunk_count;i++) { |
135 | 135 | s->types[i] = read_uint32(s->fd); | ... | ... |
block-vvfat.c
... | ... | @@ -101,7 +101,7 @@ static inline int array_ensure_allocated(array_t* array, int index) |
101 | 101 | { |
102 | 102 | if((index + 1) * array->item_size > array->size) { |
103 | 103 | int new_size = (index + 32) * array->item_size; |
104 | - array->pointer = realloc(array->pointer, new_size); | |
104 | + array->pointer = qemu_realloc(array->pointer, new_size); | |
105 | 105 | if (!array->pointer) |
106 | 106 | return -1; |
107 | 107 | array->size = new_size; |
... | ... | @@ -127,7 +127,7 @@ static inline void* array_get_next(array_t* array) { |
127 | 127 | static inline void* array_insert(array_t* array,unsigned int index,unsigned int count) { |
128 | 128 | if((array->next+count)*array->item_size>array->size) { |
129 | 129 | int increment=count*array->item_size; |
130 | - array->pointer=realloc(array->pointer,array->size+increment); | |
130 | + array->pointer=qemu_realloc(array->pointer,array->size+increment); | |
131 | 131 | if(!array->pointer) |
132 | 132 | return 0; |
133 | 133 | array->size+=increment; | ... | ... |
hw/blizzard.c
... | ... | @@ -192,7 +192,7 @@ static int blizzard_transfer_setup(struct blizzard_s *s) |
192 | 192 | s->data.len = s->bpp * s->data.dx * s->data.dy; |
193 | 193 | s->data.pitch = s->data.dx; |
194 | 194 | if (s->data.len > s->data.buflen) { |
195 | - s->data.buf = realloc(s->data.buf, s->data.len); | |
195 | + s->data.buf = qemu_realloc(s->data.buf, s->data.len); | |
196 | 196 | s->data.buflen = s->data.len; |
197 | 197 | } |
198 | 198 | s->data.ptr = s->data.buf; | ... | ... |
hw/lsi53c895a.c
... | ... | @@ -501,7 +501,7 @@ static void lsi_queue_command(LSIState *s) |
501 | 501 | DPRINTF("Queueing tag=0x%x\n", s->current_tag); |
502 | 502 | if (s->queue_len == s->active_commands) { |
503 | 503 | s->queue_len++; |
504 | - s->queue = realloc(s->queue, s->queue_len * sizeof(lsi_queue)); | |
504 | + s->queue = qemu_realloc(s->queue, s->queue_len * sizeof(lsi_queue)); | |
505 | 505 | } |
506 | 506 | p = &s->queue[s->active_commands++]; |
507 | 507 | p->tag = s->current_tag; | ... | ... |
hw/rtl8139.c
... | ... | @@ -2001,7 +2001,7 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) |
2001 | 2001 | while (s->cplus_txbuffer && s->cplus_txbuffer_offset + txsize >= s->cplus_txbuffer_len) |
2002 | 2002 | { |
2003 | 2003 | s->cplus_txbuffer_len += CP_TX_BUFFER_SIZE; |
2004 | - s->cplus_txbuffer = realloc(s->cplus_txbuffer, s->cplus_txbuffer_len); | |
2004 | + s->cplus_txbuffer = qemu_realloc(s->cplus_txbuffer, s->cplus_txbuffer_len); | |
2005 | 2005 | |
2006 | 2006 | DEBUG_PRINT(("RTL8139: +++ C+ mode transmission buffer space changed to %d\n", s->cplus_txbuffer_len)); |
2007 | 2007 | } | ... | ... |
hw/soc_dma.c
... | ... | @@ -50,7 +50,7 @@ static int fifo_size; |
50 | 50 | void transfer_fifo2fifo(struct soc_dma_ch_s *ch) |
51 | 51 | { |
52 | 52 | if (ch->bytes > fifo_size) |
53 | - fifo_buf = realloc(fifo_buf, fifo_size = ch->bytes); | |
53 | + fifo_buf = qemu_realloc(fifo_buf, fifo_size = ch->bytes); | |
54 | 54 | |
55 | 55 | /* Implement as transfer_fifo2linear + transfer_linear2fifo. */ |
56 | 56 | 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, |
262 | 262 | struct memmap_entry_s *entry; |
263 | 263 | struct dma_s *dma = (struct dma_s *) soc; |
264 | 264 | |
265 | - dma->memmap = realloc(dma->memmap, sizeof(*entry) * | |
265 | + dma->memmap = qemu_realloc(dma->memmap, sizeof(*entry) * | |
266 | 266 | (dma->memmap_size + 1)); |
267 | 267 | entry = soc_dma_lookup(dma, virt_base); |
268 | 268 | |
... | ... | @@ -314,7 +314,7 @@ void soc_dma_port_add_mem(struct soc_dma_s *soc, uint8_t *phys_base, |
314 | 314 | struct memmap_entry_s *entry; |
315 | 315 | struct dma_s *dma = (struct dma_s *) soc; |
316 | 316 | |
317 | - dma->memmap = realloc(dma->memmap, sizeof(*entry) * | |
317 | + dma->memmap = qemu_realloc(dma->memmap, sizeof(*entry) * | |
318 | 318 | (dma->memmap_size + 1)); |
319 | 319 | entry = soc_dma_lookup(dma, virt_base); |
320 | 320 | ... | ... |
qemu-common.h
... | ... | @@ -87,6 +87,7 @@ int stristart(const char *str, const char *val, const char **ptr); |
87 | 87 | time_t mktimegm(struct tm *tm); |
88 | 88 | |
89 | 89 | void *qemu_malloc(size_t size); |
90 | +void *qemu_realloc(void *ptr, size_t size); | |
90 | 91 | void *qemu_mallocz(size_t size); |
91 | 92 | void qemu_free(void *ptr); |
92 | 93 | char *qemu_strdup(const char *str); | ... | ... |
qemu-malloc.c
vnc.c
... | ... | @@ -291,8 +291,8 @@ static void vnc_dpy_resize(DisplayState *ds, int w, int h) |
291 | 291 | int size_changed; |
292 | 292 | VncState *vs = ds->opaque; |
293 | 293 | |
294 | - ds->data = realloc(ds->data, w * h * vs->depth); | |
295 | - vs->old_data = realloc(vs->old_data, w * h * vs->depth); | |
294 | + ds->data = qemu_realloc(ds->data, w * h * vs->depth); | |
295 | + vs->old_data = qemu_realloc(vs->old_data, w * h * vs->depth); | |
296 | 296 | |
297 | 297 | if (ds->data == NULL || vs->old_data == NULL) { |
298 | 298 | fprintf(stderr, "vnc: memory allocation failed\n"); |
... | ... | @@ -611,7 +611,7 @@ static void buffer_reserve(Buffer *buffer, size_t len) |
611 | 611 | { |
612 | 612 | if ((buffer->capacity - buffer->offset) < len) { |
613 | 613 | buffer->capacity += (len + 1024); |
614 | - buffer->buffer = realloc(buffer->buffer, buffer->capacity); | |
614 | + buffer->buffer = qemu_realloc(buffer->buffer, buffer->capacity); | |
615 | 615 | if (buffer->buffer == NULL) { |
616 | 616 | fprintf(stderr, "vnc: out of memory\n"); |
617 | 617 | exit(1); | ... | ... |