Add qemu_realloc(), by Gerd Hoffmann.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4986 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
bf6bca527c
commit
2137b4cca9
10
block-dmg.c
10
block-dmg.c
|
@ -125,11 +125,11 @@ dmg_close:
|
||||||
goto dmg_close;
|
goto dmg_close;
|
||||||
chunk_count = (count-204)/40;
|
chunk_count = (count-204)/40;
|
||||||
new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count);
|
new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count);
|
||||||
s->types = realloc(s->types, new_size/2);
|
s->types = qemu_realloc(s->types, new_size/2);
|
||||||
s->offsets = realloc(s->offsets, new_size);
|
s->offsets = qemu_realloc(s->offsets, new_size);
|
||||||
s->lengths = realloc(s->lengths, new_size);
|
s->lengths = qemu_realloc(s->lengths, new_size);
|
||||||
s->sectors = realloc(s->sectors, new_size);
|
s->sectors = qemu_realloc(s->sectors, new_size);
|
||||||
s->sectorcounts = realloc(s->sectorcounts, new_size);
|
s->sectorcounts = qemu_realloc(s->sectorcounts, new_size);
|
||||||
|
|
||||||
for(i=s->n_chunks;i<s->n_chunks+chunk_count;i++) {
|
for(i=s->n_chunks;i<s->n_chunks+chunk_count;i++) {
|
||||||
s->types[i] = read_uint32(s->fd);
|
s->types[i] = read_uint32(s->fd);
|
||||||
|
|
|
@ -101,7 +101,7 @@ static inline int array_ensure_allocated(array_t* array, int index)
|
||||||
{
|
{
|
||||||
if((index + 1) * array->item_size > array->size) {
|
if((index + 1) * array->item_size > array->size) {
|
||||||
int new_size = (index + 32) * array->item_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)
|
if (!array->pointer)
|
||||||
return -1;
|
return -1;
|
||||||
array->size = new_size;
|
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) {
|
static inline void* array_insert(array_t* array,unsigned int index,unsigned int count) {
|
||||||
if((array->next+count)*array->item_size>array->size) {
|
if((array->next+count)*array->item_size>array->size) {
|
||||||
int increment=count*array->item_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)
|
if(!array->pointer)
|
||||||
return 0;
|
return 0;
|
||||||
array->size+=increment;
|
array->size+=increment;
|
||||||
|
|
|
@ -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.len = s->bpp * s->data.dx * s->data.dy;
|
||||||
s->data.pitch = s->data.dx;
|
s->data.pitch = s->data.dx;
|
||||||
if (s->data.len > s->data.buflen) {
|
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.buflen = s->data.len;
|
||||||
}
|
}
|
||||||
s->data.ptr = s->data.buf;
|
s->data.ptr = s->data.buf;
|
||||||
|
|
|
@ -501,7 +501,7 @@ static void lsi_queue_command(LSIState *s)
|
||||||
DPRINTF("Queueing tag=0x%x\n", s->current_tag);
|
DPRINTF("Queueing tag=0x%x\n", s->current_tag);
|
||||||
if (s->queue_len == s->active_commands) {
|
if (s->queue_len == s->active_commands) {
|
||||||
s->queue_len++;
|
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 = &s->queue[s->active_commands++];
|
||||||
p->tag = s->current_tag;
|
p->tag = s->current_tag;
|
||||||
|
|
|
@ -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)
|
while (s->cplus_txbuffer && s->cplus_txbuffer_offset + txsize >= s->cplus_txbuffer_len)
|
||||||
{
|
{
|
||||||
s->cplus_txbuffer_len += CP_TX_BUFFER_SIZE;
|
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));
|
DEBUG_PRINT(("RTL8139: +++ C+ mode transmission buffer space changed to %d\n", s->cplus_txbuffer_len));
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ static int fifo_size;
|
||||||
void transfer_fifo2fifo(struct soc_dma_ch_s *ch)
|
void transfer_fifo2fifo(struct soc_dma_ch_s *ch)
|
||||||
{
|
{
|
||||||
if (ch->bytes > fifo_size)
|
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. */
|
/* Implement as transfer_fifo2linear + transfer_linear2fifo. */
|
||||||
ch->io_fn[0](ch->io_opaque[0], fifo_buf, ch->bytes);
|
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 memmap_entry_s *entry;
|
||||||
struct dma_s *dma = (struct dma_s *) soc;
|
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));
|
(dma->memmap_size + 1));
|
||||||
entry = soc_dma_lookup(dma, virt_base);
|
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 memmap_entry_s *entry;
|
||||||
struct dma_s *dma = (struct dma_s *) soc;
|
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));
|
(dma->memmap_size + 1));
|
||||||
entry = soc_dma_lookup(dma, virt_base);
|
entry = soc_dma_lookup(dma, virt_base);
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,7 @@ int stristart(const char *str, const char *val, const char **ptr);
|
||||||
time_t mktimegm(struct tm *tm);
|
time_t mktimegm(struct tm *tm);
|
||||||
|
|
||||||
void *qemu_malloc(size_t size);
|
void *qemu_malloc(size_t size);
|
||||||
|
void *qemu_realloc(void *ptr, size_t size);
|
||||||
void *qemu_mallocz(size_t size);
|
void *qemu_mallocz(size_t size);
|
||||||
void qemu_free(void *ptr);
|
void qemu_free(void *ptr);
|
||||||
char *qemu_strdup(const char *str);
|
char *qemu_strdup(const char *str);
|
||||||
|
|
|
@ -38,6 +38,11 @@ void *qemu_malloc(size_t size)
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *qemu_realloc(void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
return realloc(ptr, size);
|
||||||
|
}
|
||||||
|
|
||||||
void *qemu_mallocz(size_t size)
|
void *qemu_mallocz(size_t size)
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
6
vnc.c
6
vnc.c
|
@ -291,8 +291,8 @@ static void vnc_dpy_resize(DisplayState *ds, int w, int h)
|
||||||
int size_changed;
|
int size_changed;
|
||||||
VncState *vs = ds->opaque;
|
VncState *vs = ds->opaque;
|
||||||
|
|
||||||
ds->data = realloc(ds->data, w * h * vs->depth);
|
ds->data = qemu_realloc(ds->data, w * h * vs->depth);
|
||||||
vs->old_data = realloc(vs->old_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) {
|
if (ds->data == NULL || vs->old_data == NULL) {
|
||||||
fprintf(stderr, "vnc: memory allocation failed\n");
|
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) {
|
if ((buffer->capacity - buffer->offset) < len) {
|
||||||
buffer->capacity += (len + 1024);
|
buffer->capacity += (len + 1024);
|
||||||
buffer->buffer = realloc(buffer->buffer, buffer->capacity);
|
buffer->buffer = qemu_realloc(buffer->buffer, buffer->capacity);
|
||||||
if (buffer->buffer == NULL) {
|
if (buffer->buffer == NULL) {
|
||||||
fprintf(stderr, "vnc: out of memory\n");
|
fprintf(stderr, "vnc: out of memory\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
Loading…
Reference in New Issue