Commit 7267c094 authored by Anthony Liguori's avatar Anthony Liguori

Use glib memory allocation and free functions

qemu_malloc/qemu_free no longer exist after this commit.
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
parent 14015304
......@@ -55,8 +55,8 @@ qemu_acl *qemu_acl_init(const char *aclname)
if (acl)
return acl;
acl = qemu_malloc(sizeof(*acl));
acl->aclname = qemu_strdup(aclname);
acl = g_malloc(sizeof(*acl));
acl->aclname = g_strdup(aclname);
/* Deny by default, so there is no window of "open
* access" between QEMU starting, and the user setting
* up ACLs in the monitor */
......@@ -65,7 +65,7 @@ qemu_acl *qemu_acl_init(const char *aclname)
acl->nentries = 0;
QTAILQ_INIT(&acl->entries);
acls = qemu_realloc(acls, sizeof(*acls) * (nacls +1));
acls = g_realloc(acls, sizeof(*acls) * (nacls +1));
acls[nacls] = acl;
nacls++;
......@@ -116,8 +116,8 @@ int qemu_acl_append(qemu_acl *acl,
{
qemu_acl_entry *entry;
entry = qemu_malloc(sizeof(*entry));
entry->match = qemu_strdup(match);
entry = g_malloc(sizeof(*entry));
entry->match = g_strdup(match);
entry->deny = deny;
QTAILQ_INSERT_TAIL(&acl->entries, entry, next);
......@@ -142,8 +142,8 @@ int qemu_acl_insert(qemu_acl *acl,
return qemu_acl_append(acl, deny, match);
entry = qemu_malloc(sizeof(*entry));
entry->match = qemu_strdup(match);
entry = g_malloc(sizeof(*entry));
entry->match = g_strdup(match);
entry->deny = deny;
QTAILQ_FOREACH(tmp, &acl->entries, next) {
......
......@@ -75,13 +75,13 @@ int qemu_aio_set_fd_handler(int fd,
* releasing the walking_handlers lock.
*/
QLIST_REMOVE(node, node);
qemu_free(node);
g_free(node);
}
}
} else {
if (node == NULL) {
/* Alloc and insert if it's not already there */
node = qemu_mallocz(sizeof(AioHandler));
node = g_malloc0(sizeof(AioHandler));
node->fd = fd;
QLIST_INSERT_HEAD(&aio_handlers, node, node);
}
......@@ -220,7 +220,7 @@ void qemu_aio_wait(void)
if (tmp->deleted) {
QLIST_REMOVE(tmp, node);
qemu_free(tmp);
g_free(tmp);
}
}
......
......@@ -235,7 +235,7 @@ static void sort_ram_list(void)
QLIST_FOREACH(block, &ram_list.blocks, next) {
++n;
}
blocks = qemu_malloc(n * sizeof *blocks);
blocks = g_malloc(n * sizeof *blocks);
n = 0;
QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
blocks[n++] = block;
......@@ -245,7 +245,7 @@ static void sort_ram_list(void)
while (--n >= 0) {
QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next);
}
qemu_free(blocks);
g_free(blocks);
}
int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
......
......@@ -43,7 +43,7 @@ struct QEMUBH {
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
{
QEMUBH *bh;
bh = qemu_mallocz(sizeof(QEMUBH));
bh = g_malloc0(sizeof(QEMUBH));
bh->cb = cb;
bh->opaque = opaque;
bh->next = first_bh;
......@@ -74,7 +74,7 @@ int qemu_bh_poll(void)
bh = *bhp;
if (bh->deleted) {
*bhp = bh->next;
qemu_free(bh);
g_free(bh);
} else
bhp = &bh->next;
}
......
......@@ -136,7 +136,7 @@ static void alsa_fini_poll (struct pollhlp *hlp)
for (i = 0; i < hlp->count; ++i) {
qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);
}
qemu_free (pfds);
g_free (pfds);
}
hlp->pfds = NULL;
hlp->count = 0;
......@@ -260,7 +260,7 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)
if (err < 0) {
alsa_logerr (err, "Could not initialize poll mode\n"
"Could not obtain poll descriptors\n");
qemu_free (pfds);
g_free (pfds);
return -1;
}
......@@ -288,7 +288,7 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)
while (i--) {
qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);
}
qemu_free (pfds);
g_free (pfds);
return -1;
}
}
......@@ -816,7 +816,7 @@ static void alsa_fini_out (HWVoiceOut *hw)
alsa_anal_close (&alsa->handle, &alsa->pollhlp);
if (alsa->pcm_buf) {
qemu_free (alsa->pcm_buf);
g_free (alsa->pcm_buf);
alsa->pcm_buf = NULL;
}
}
......@@ -979,7 +979,7 @@ static void alsa_fini_in (HWVoiceIn *hw)
alsa_anal_close (&alsa->handle, &alsa->pollhlp);
if (alsa->pcm_buf) {
qemu_free (alsa->pcm_buf);
g_free (alsa->pcm_buf);
alsa->pcm_buf = NULL;
}
}
......
......@@ -196,7 +196,7 @@ void *audio_calloc (const char *funcname, int nmemb, size_t size)
return NULL;
}
return qemu_mallocz (len);
return g_malloc0 (len);
}
static char *audio_alloc_prefix (const char *s)
......@@ -210,7 +210,7 @@ static char *audio_alloc_prefix (const char *s)
}
len = strlen (s);
r = qemu_malloc (len + sizeof (qemu_prefix));
r = g_malloc (len + sizeof (qemu_prefix));
u = r + sizeof (qemu_prefix) - 1;
......@@ -425,7 +425,7 @@ static void audio_print_options (const char *prefix,
printf (" %s\n", opt->descr);
}
qemu_free (uprefix);
g_free (uprefix);
}
static void audio_process_options (const char *prefix,
......@@ -462,7 +462,7 @@ static void audio_process_options (const char *prefix,
* (includes trailing zero) + zero + underscore (on behalf of
* sizeof) */
optlen = len + preflen + sizeof (qemu_prefix) + 1;
optname = qemu_malloc (optlen);
optname = g_malloc (optlen);
pstrcpy (optname, optlen, qemu_prefix);
......@@ -507,7 +507,7 @@ static void audio_process_options (const char *prefix,
opt->overriddenp = &opt->overridden;
}
*opt->overriddenp = !def;
qemu_free (optname);
g_free (optname);
}
}
......@@ -778,7 +778,7 @@ static void audio_detach_capture (HWVoiceOut *hw)
QLIST_REMOVE (sw, entries);
QLIST_REMOVE (sc, entries);
qemu_free (sc);
g_free (sc);
if (was_active) {
/* We have removed soft voice from the capture:
this might have changed the overall status of the capture
......@@ -818,7 +818,7 @@ static int audio_attach_capture (HWVoiceOut *hw)
sw->rate = st_rate_start (sw->info.freq, hw_cap->info.freq);
if (!sw->rate) {
dolog ("Could not start rate conversion for `%s'\n", SW_NAME (sw));
qemu_free (sw);
g_free (sw);
return -1;
}
QLIST_INSERT_HEAD (&hw_cap->sw_head, sw, entries);
......@@ -1907,7 +1907,7 @@ static void audio_init (void)
void AUD_register_card (const char *name, QEMUSoundCard *card)
{
audio_init ();
card->name = qemu_strdup (name);
card->name = g_strdup (name);
memset (&card->entries, 0, sizeof (card->entries));
QLIST_INSERT_HEAD (&glob_audio_state.card_head, card, entries);
}
......@@ -1915,7 +1915,7 @@ void AUD_register_card (const char *name, QEMUSoundCard *card)
void AUD_remove_card (QEMUSoundCard *card)
{
QLIST_REMOVE (card, entries);
qemu_free (card->name);
g_free (card->name);
}
......@@ -2000,11 +2000,11 @@ CaptureVoiceOut *AUD_add_capture (
return cap;
err3:
qemu_free (cap->hw.mix_buf);
g_free (cap->hw.mix_buf);
err2:
qemu_free (cap);
g_free (cap);
err1:
qemu_free (cb);
g_free (cb);
err0:
return NULL;
}
......@@ -2018,7 +2018,7 @@ void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque)
if (cb->opaque == cb_opaque) {
cb->ops.destroy (cb_opaque);
QLIST_REMOVE (cb, entries);
qemu_free (cb);
g_free (cb);
if (!cap->cb_head.lh_first) {
SWVoiceOut *sw = cap->hw.sw_head.lh_first, *sw1;
......@@ -2036,11 +2036,11 @@ void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque)
}
QLIST_REMOVE (sw, entries);
QLIST_REMOVE (sc, entries);
qemu_free (sc);
g_free (sc);
sw = sw1;
}
QLIST_REMOVE (cap, entries);
qemu_free (cap);
g_free (cap);
}
return;
}
......
......@@ -72,7 +72,7 @@ static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv)
static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
{
if (HWBUF) {
qemu_free (HWBUF);
g_free (HWBUF);
}
HWBUF = NULL;
......@@ -93,7 +93,7 @@ static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
{
if (sw->buf) {
qemu_free (sw->buf);
g_free (sw->buf);
}
if (sw->rate) {
......@@ -123,7 +123,7 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw)
sw->rate = st_rate_start (sw->hw->info.freq, sw->info.freq);
#endif
if (!sw->rate) {
qemu_free (sw->buf);
g_free (sw->buf);
sw->buf = NULL;
return -1;
}
......@@ -160,10 +160,10 @@ static int glue (audio_pcm_sw_init_, TYPE) (
[sw->info.swap_endianness]
[audio_bits_to_index (sw->info.bits)];
sw->name = qemu_strdup (name);
sw->name = g_strdup (name);
err = glue (audio_pcm_sw_alloc_resources_, TYPE) (sw);
if (err) {
qemu_free (sw->name);
g_free (sw->name);
sw->name = NULL;
}
return err;
......@@ -173,7 +173,7 @@ static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw)
{
glue (audio_pcm_sw_free_resources_, TYPE) (sw);
if (sw->name) {
qemu_free (sw->name);
g_free (sw->name);
sw->name = NULL;
}
}
......@@ -201,7 +201,7 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
glue (s->nb_hw_voices_, TYPE) += 1;
glue (audio_pcm_hw_free_resources_ ,TYPE) (hw);
glue (hw->pcm_ops->fini_, TYPE) (hw);
qemu_free (hw);
g_free (hw);
*hwp = NULL;
}
}
......@@ -300,7 +300,7 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)
err1:
glue (hw->pcm_ops->fini_, TYPE) (hw);
err0:
qemu_free (hw);
g_free (hw);
return NULL;
}
......@@ -368,7 +368,7 @@ err3:
glue (audio_pcm_hw_del_sw_, TYPE) (sw);
glue (audio_pcm_hw_gc_, TYPE) (&hw);
err2:
qemu_free (sw);
g_free (sw);
err1:
return NULL;
}
......@@ -378,7 +378,7 @@ static void glue (audio_close_, TYPE) (SW *sw)
glue (audio_pcm_sw_fini_, TYPE) (sw);
glue (audio_pcm_hw_del_sw_, TYPE) (sw);
glue (audio_pcm_hw_gc_, TYPE) (&sw->hw);
qemu_free (sw);
g_free (sw);
}
void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw)
......
......@@ -246,7 +246,7 @@ static int qesd_init_out (HWVoiceOut *hw, struct audsettings *as)
esd->fd = -1;
fail1:
qemu_free (esd->pcm_buf);
g_free (esd->pcm_buf);
esd->pcm_buf = NULL;
return -1;
}
......@@ -270,7 +270,7 @@ static void qesd_fini_out (HWVoiceOut *hw)
audio_pt_fini (&esd->pt, AUDIO_FUNC);
qemu_free (esd->pcm_buf);
g_free (esd->pcm_buf);
esd->pcm_buf = NULL;
}
......@@ -453,7 +453,7 @@ static int qesd_init_in (HWVoiceIn *hw, struct audsettings *as)
esd->fd = -1;
fail1:
qemu_free (esd->pcm_buf);
g_free (esd->pcm_buf);
esd->pcm_buf = NULL;
return -1;
}
......@@ -477,7 +477,7 @@ static void qesd_fini_in (HWVoiceIn *hw)
audio_pt_fini (&esd->pt, AUDIO_FUNC);
qemu_free (esd->pcm_buf);
g_free (esd->pcm_buf);
esd->pcm_buf = NULL;
}
......
......@@ -326,7 +326,7 @@ void *st_rate_start (int inrate, int outrate)
void st_rate_stop (void *opaque)
{
qemu_free (opaque);
g_free (opaque);
}
void mixeng_clear (struct st_sample *buf, int len)
......
......@@ -508,7 +508,7 @@ static void oss_fini_out (HWVoiceOut *hw)
}
}
else {
qemu_free (oss->pcm_buf);
g_free (oss->pcm_buf);
}
oss->pcm_buf = NULL;
}
......@@ -741,7 +741,7 @@ static void oss_fini_in (HWVoiceIn *hw)
oss_anal_close (&oss->fd);
if (oss->pcm_buf) {
qemu_free (oss->pcm_buf);
g_free (oss->pcm_buf);
oss->pcm_buf = NULL;
}
}
......
......@@ -339,7 +339,7 @@ static int qpa_init_out (HWVoiceOut *hw, struct audsettings *as)
return 0;
fail3:
qemu_free (pa->pcm_buf);
g_free (pa->pcm_buf);
pa->pcm_buf = NULL;
fail2:
pa_simple_free (pa->s);
......@@ -394,7 +394,7 @@ static int qpa_init_in (HWVoiceIn *hw, struct audsettings *as)
return 0;
fail3:
qemu_free (pa->pcm_buf);
g_free (pa->pcm_buf);
pa->pcm_buf = NULL;
fail2:
pa_simple_free (pa->s);
......@@ -419,7 +419,7 @@ static void qpa_fini_out (HWVoiceOut *hw)
}
audio_pt_fini (&pa->pt, AUDIO_FUNC);
qemu_free (pa->pcm_buf);
g_free (pa->pcm_buf);
pa->pcm_buf = NULL;
}
......@@ -439,7 +439,7 @@ static void qpa_fini_in (HWVoiceIn *hw)
}
audio_pt_fini (&pa->pt, AUDIO_FUNC);
qemu_free (pa->pcm_buf);
g_free (pa->pcm_buf);
pa->pcm_buf = NULL;
}
......
......@@ -156,7 +156,7 @@ static int wav_init_out (HWVoiceOut *hw, struct audsettings *as)
if (!wav->f) {
dolog ("Failed to open wave file `%s'\nReason: %s\n",
conf.wav_path, strerror (errno));
qemu_free (wav->pcm_buf);
g_free (wav->pcm_buf);
wav->pcm_buf = NULL;
return -1;
}
......@@ -189,7 +189,7 @@ static void wav_fini_out (HWVoiceOut *hw)
qemu_fclose (wav->f);
wav->f = NULL;
qemu_free (wav->pcm_buf);
g_free (wav->pcm_buf);
wav->pcm_buf = NULL;
}
......
......@@ -48,7 +48,7 @@ static void wav_destroy (void *opaque)
qemu_fclose (wav->f);
}
qemu_free (wav->path);
g_free (wav->path);
}
static void wav_capture (void *opaque, void *buf, int size)
......@@ -120,7 +120,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
ops.capture = wav_capture;
ops.destroy = wav_destroy;
wav = qemu_mallocz (sizeof (*wav));
wav = g_malloc0 (sizeof (*wav));
shift = bits16 + stereo;
hdr[34] = bits16 ? 0x10 : 0x08;
......@@ -134,11 +134,11 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
if (!wav->f) {
monitor_printf(mon, "Failed to open wave file `%s'\nReason: %s\n",
path, strerror (errno));
qemu_free (wav);
g_free (wav);
return -1;
}
wav->path = qemu_strdup (path);
wav->path = g_strdup (path);
wav->bits = bits;
wav->nchannels = nchannels;
wav->freq = freq;
......@@ -148,9 +148,9 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
cap = AUD_add_capture (&as, &ops, wav);
if (!cap) {
monitor_printf(mon, "Failed to add audio capture\n");
qemu_free (wav->path);
g_free (wav->path);
qemu_fclose (wav->f);
qemu_free (wav);
g_free (wav);
return -1;
}
......
......@@ -222,9 +222,9 @@ static int winwave_init_out (HWVoiceOut *hw, struct audsettings *as)
return 0;
err4:
qemu_free (wave->pcm_buf);
g_free (wave->pcm_buf);
err3:
qemu_free (wave->hdrs);
g_free (wave->hdrs);
err2:
winwave_anal_close_out (wave);
err1:
......@@ -310,10 +310,10 @@ static void winwave_fini_out (HWVoiceOut *hw)
wave->event = NULL;
}
qemu_free (wave->pcm_buf);
g_free (wave->pcm_buf);
wave->pcm_buf = NULL;
qemu_free (wave->hdrs);
g_free (wave->hdrs);
wave->hdrs = NULL;
}
......@@ -511,9 +511,9 @@ static int winwave_init_in (HWVoiceIn *hw, struct audsettings *as)
return 0;
err4:
qemu_free (wave->pcm_buf);
g_free (wave->pcm_buf);
err3:
qemu_free (wave->hdrs);
g_free (wave->hdrs);
err2:
winwave_anal_close_in (wave);
err1:
......@@ -550,10 +550,10 @@ static void winwave_fini_in (HWVoiceIn *hw)
wave->event = NULL;
}
qemu_free (wave->pcm_buf);
g_free (wave->pcm_buf);
wave->pcm_buf = NULL;
qemu_free (wave->hdrs);
g_free (wave->hdrs);
wave->hdrs = NULL;
}
......
......@@ -91,7 +91,7 @@ int slow_bitmap_intersects(const unsigned long *bitmap1,
static inline unsigned long *bitmap_new(int nbits)
{
int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
return qemu_mallocz(len);
return g_malloc0(len);
}
static inline void bitmap_zero(unsigned long *dst, int nbits)
......
......@@ -180,7 +180,7 @@ static void alloc_aio_bitmap(BlkMigDevState *bmds)
BDRV_SECTORS_PER_DIRTY_CHUNK * 8 - 1;
bitmap_size /= BDRV_SECTORS_PER_DIRTY_CHUNK * 8;
bmds->aio_bitmap = qemu_mallocz(bitmap_size);
bmds->aio_bitmap = g_malloc0(bitmap_size);
}
static void blk_mig_read_cb(void *opaque, int ret)
......@@ -235,8 +235,8 @@ static int mig_save_device_bulk(Monitor *mon, QEMUFile *f,
nr_sectors = total_sectors - cur_sector;
}
blk = qemu_malloc(sizeof(BlkMigBlock));
blk->buf = qemu_malloc(BLOCK_SIZE);
blk = g_malloc(sizeof(BlkMigBlock));
blk->buf = g_malloc(BLOCK_SIZE);
blk->bmds = bmds;
blk->sector = cur_sector;
blk->nr_sectors = nr_sectors;
......@@ -264,8 +264,8 @@ static int mig_save_device_bulk(Monitor *mon, QEMUFile *f,
error:
monitor_printf(mon, "Error reading sector %" PRId64 "\n", cur_sector);
qemu_file_set_error(f);
qemu_free(blk->buf);
qemu_free(blk);
g_free(blk->buf);
g_free(blk);
return 0;
}
......@@ -290,7 +290,7 @@ static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
return;
}
bmds = qemu_mallocz(sizeof(BlkMigDevState));
bmds = g_malloc0(sizeof(BlkMigDevState));
bmds->bs = bs;
bmds->bulk_completed = 0;
bmds->total_sectors = sectors;
......@@ -395,8 +395,8 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f,
} else {
nr_sectors = BDRV_SECTORS_PER_DIRTY_CHU