Skip to content

Commit 7267c09

Browse files
author
Anthony Liguori
committed
Use glib memory allocation and free functions
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <[email protected]>
1 parent 1401530 commit 7267c09

File tree

357 files changed

+1672
-1674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

357 files changed

+1672
-1674
lines changed

acl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ qemu_acl *qemu_acl_init(const char *aclname)
5555
if (acl)
5656
return acl;
5757

58-
acl = qemu_malloc(sizeof(*acl));
59-
acl->aclname = qemu_strdup(aclname);
58+
acl = g_malloc(sizeof(*acl));
59+
acl->aclname = g_strdup(aclname);
6060
/* Deny by default, so there is no window of "open
6161
* access" between QEMU starting, and the user setting
6262
* up ACLs in the monitor */
@@ -65,7 +65,7 @@ qemu_acl *qemu_acl_init(const char *aclname)
6565
acl->nentries = 0;
6666
QTAILQ_INIT(&acl->entries);
6767

68-
acls = qemu_realloc(acls, sizeof(*acls) * (nacls +1));
68+
acls = g_realloc(acls, sizeof(*acls) * (nacls +1));
6969
acls[nacls] = acl;
7070
nacls++;
7171

@@ -116,8 +116,8 @@ int qemu_acl_append(qemu_acl *acl,
116116
{
117117
qemu_acl_entry *entry;
118118

119-
entry = qemu_malloc(sizeof(*entry));
120-
entry->match = qemu_strdup(match);
119+
entry = g_malloc(sizeof(*entry));
120+
entry->match = g_strdup(match);
121121
entry->deny = deny;
122122

123123
QTAILQ_INSERT_TAIL(&acl->entries, entry, next);
@@ -142,8 +142,8 @@ int qemu_acl_insert(qemu_acl *acl,
142142
return qemu_acl_append(acl, deny, match);
143143

144144

145-
entry = qemu_malloc(sizeof(*entry));
146-
entry->match = qemu_strdup(match);
145+
entry = g_malloc(sizeof(*entry));
146+
entry->match = g_strdup(match);
147147
entry->deny = deny;
148148

149149
QTAILQ_FOREACH(tmp, &acl->entries, next) {

aio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ int qemu_aio_set_fd_handler(int fd,
7575
* releasing the walking_handlers lock.
7676
*/
7777
QLIST_REMOVE(node, node);
78-
qemu_free(node);
78+
g_free(node);
7979
}
8080
}
8181
} else {
8282
if (node == NULL) {
8383
/* Alloc and insert if it's not already there */
84-
node = qemu_mallocz(sizeof(AioHandler));
84+
node = g_malloc0(sizeof(AioHandler));
8585
node->fd = fd;
8686
QLIST_INSERT_HEAD(&aio_handlers, node, node);
8787
}
@@ -220,7 +220,7 @@ void qemu_aio_wait(void)
220220

221221
if (tmp->deleted) {
222222
QLIST_REMOVE(tmp, node);
223-
qemu_free(tmp);
223+
g_free(tmp);
224224
}
225225
}
226226

arch_init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static void sort_ram_list(void)
235235
QLIST_FOREACH(block, &ram_list.blocks, next) {
236236
++n;
237237
}
238-
blocks = qemu_malloc(n * sizeof *blocks);
238+
blocks = g_malloc(n * sizeof *blocks);
239239
n = 0;
240240
QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
241241
blocks[n++] = block;
@@ -245,7 +245,7 @@ static void sort_ram_list(void)
245245
while (--n >= 0) {
246246
QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next);
247247
}
248-
qemu_free(blocks);
248+
g_free(blocks);
249249
}
250250

251251
int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)

async.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct QEMUBH {
4343
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
4444
{
4545
QEMUBH *bh;
46-
bh = qemu_mallocz(sizeof(QEMUBH));
46+
bh = g_malloc0(sizeof(QEMUBH));
4747
bh->cb = cb;
4848
bh->opaque = opaque;
4949
bh->next = first_bh;
@@ -74,7 +74,7 @@ int qemu_bh_poll(void)
7474
bh = *bhp;
7575
if (bh->deleted) {
7676
*bhp = bh->next;
77-
qemu_free(bh);
77+
g_free(bh);
7878
} else
7979
bhp = &bh->next;
8080
}

audio/alsaaudio.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static void alsa_fini_poll (struct pollhlp *hlp)
136136
for (i = 0; i < hlp->count; ++i) {
137137
qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);
138138
}
139-
qemu_free (pfds);
139+
g_free (pfds);
140140
}
141141
hlp->pfds = NULL;
142142
hlp->count = 0;
@@ -260,7 +260,7 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)
260260
if (err < 0) {
261261
alsa_logerr (err, "Could not initialize poll mode\n"
262262
"Could not obtain poll descriptors\n");
263-
qemu_free (pfds);
263+
g_free (pfds);
264264
return -1;
265265
}
266266

@@ -288,7 +288,7 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)
288288
while (i--) {
289289
qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);
290290
}
291-
qemu_free (pfds);
291+
g_free (pfds);
292292
return -1;
293293
}
294294
}
@@ -816,7 +816,7 @@ static void alsa_fini_out (HWVoiceOut *hw)
816816
alsa_anal_close (&alsa->handle, &alsa->pollhlp);
817817

818818
if (alsa->pcm_buf) {
819-
qemu_free (alsa->pcm_buf);
819+
g_free (alsa->pcm_buf);
820820
alsa->pcm_buf = NULL;
821821
}
822822
}
@@ -979,7 +979,7 @@ static void alsa_fini_in (HWVoiceIn *hw)
979979
alsa_anal_close (&alsa->handle, &alsa->pollhlp);
980980

981981
if (alsa->pcm_buf) {
982-
qemu_free (alsa->pcm_buf);
982+
g_free (alsa->pcm_buf);
983983
alsa->pcm_buf = NULL;
984984
}
985985
}

audio/audio.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void *audio_calloc (const char *funcname, int nmemb, size_t size)
196196
return NULL;
197197
}
198198

199-
return qemu_mallocz (len);
199+
return g_malloc0 (len);
200200
}
201201

202202
static char *audio_alloc_prefix (const char *s)
@@ -210,7 +210,7 @@ static char *audio_alloc_prefix (const char *s)
210210
}
211211

212212
len = strlen (s);
213-
r = qemu_malloc (len + sizeof (qemu_prefix));
213+
r = g_malloc (len + sizeof (qemu_prefix));
214214

215215
u = r + sizeof (qemu_prefix) - 1;
216216

@@ -425,7 +425,7 @@ static void audio_print_options (const char *prefix,
425425
printf (" %s\n", opt->descr);
426426
}
427427

428-
qemu_free (uprefix);
428+
g_free (uprefix);
429429
}
430430

431431
static void audio_process_options (const char *prefix,
@@ -462,7 +462,7 @@ static void audio_process_options (const char *prefix,
462462
* (includes trailing zero) + zero + underscore (on behalf of
463463
* sizeof) */
464464
optlen = len + preflen + sizeof (qemu_prefix) + 1;
465-
optname = qemu_malloc (optlen);
465+
optname = g_malloc (optlen);
466466

467467
pstrcpy (optname, optlen, qemu_prefix);
468468

@@ -507,7 +507,7 @@ static void audio_process_options (const char *prefix,
507507
opt->overriddenp = &opt->overridden;
508508
}
509509
*opt->overriddenp = !def;
510-
qemu_free (optname);
510+
g_free (optname);
511511
}
512512
}
513513

@@ -778,7 +778,7 @@ static void audio_detach_capture (HWVoiceOut *hw)
778778

779779
QLIST_REMOVE (sw, entries);
780780
QLIST_REMOVE (sc, entries);
781-
qemu_free (sc);
781+
g_free (sc);
782782
if (was_active) {
783783
/* We have removed soft voice from the capture:
784784
this might have changed the overall status of the capture
@@ -818,7 +818,7 @@ static int audio_attach_capture (HWVoiceOut *hw)
818818
sw->rate = st_rate_start (sw->info.freq, hw_cap->info.freq);
819819
if (!sw->rate) {
820820
dolog ("Could not start rate conversion for `%s'\n", SW_NAME (sw));
821-
qemu_free (sw);
821+
g_free (sw);
822822
return -1;
823823
}
824824
QLIST_INSERT_HEAD (&hw_cap->sw_head, sw, entries);
@@ -1907,15 +1907,15 @@ static void audio_init (void)
19071907
void AUD_register_card (const char *name, QEMUSoundCard *card)
19081908
{
19091909
audio_init ();
1910-
card->name = qemu_strdup (name);
1910+
card->name = g_strdup (name);
19111911
memset (&card->entries, 0, sizeof (card->entries));
19121912
QLIST_INSERT_HEAD (&glob_audio_state.card_head, card, entries);
19131913
}
19141914

19151915
void AUD_remove_card (QEMUSoundCard *card)
19161916
{
19171917
QLIST_REMOVE (card, entries);
1918-
qemu_free (card->name);
1918+
g_free (card->name);
19191919
}
19201920

19211921

@@ -2000,11 +2000,11 @@ CaptureVoiceOut *AUD_add_capture (
20002000
return cap;
20012001

20022002
err3:
2003-
qemu_free (cap->hw.mix_buf);
2003+
g_free (cap->hw.mix_buf);
20042004
err2:
2005-
qemu_free (cap);
2005+
g_free (cap);
20062006
err1:
2007-
qemu_free (cb);
2007+
g_free (cb);
20082008
err0:
20092009
return NULL;
20102010
}
@@ -2018,7 +2018,7 @@ void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque)
20182018
if (cb->opaque == cb_opaque) {
20192019
cb->ops.destroy (cb_opaque);
20202020
QLIST_REMOVE (cb, entries);
2021-
qemu_free (cb);
2021+
g_free (cb);
20222022

20232023
if (!cap->cb_head.lh_first) {
20242024
SWVoiceOut *sw = cap->hw.sw_head.lh_first, *sw1;
@@ -2036,11 +2036,11 @@ void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque)
20362036
}
20372037
QLIST_REMOVE (sw, entries);
20382038
QLIST_REMOVE (sc, entries);
2039-
qemu_free (sc);
2039+
g_free (sc);
20402040
sw = sw1;
20412041
}
20422042
QLIST_REMOVE (cap, entries);
2043-
qemu_free (cap);
2043+
g_free (cap);
20442044
}
20452045
return;
20462046
}

audio/audio_template.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv)
7272
static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
7373
{
7474
if (HWBUF) {
75-
qemu_free (HWBUF);
75+
g_free (HWBUF);
7676
}
7777

7878
HWBUF = NULL;
@@ -93,7 +93,7 @@ static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
9393
static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
9494
{
9595
if (sw->buf) {
96-
qemu_free (sw->buf);
96+
g_free (sw->buf);
9797
}
9898

9999
if (sw->rate) {
@@ -123,7 +123,7 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw)
123123
sw->rate = st_rate_start (sw->hw->info.freq, sw->info.freq);
124124
#endif
125125
if (!sw->rate) {
126-
qemu_free (sw->buf);
126+
g_free (sw->buf);
127127
sw->buf = NULL;
128128
return -1;
129129
}
@@ -160,10 +160,10 @@ static int glue (audio_pcm_sw_init_, TYPE) (
160160
[sw->info.swap_endianness]
161161
[audio_bits_to_index (sw->info.bits)];
162162

163-
sw->name = qemu_strdup (name);
163+
sw->name = g_strdup (name);
164164
err = glue (audio_pcm_sw_alloc_resources_, TYPE) (sw);
165165
if (err) {
166-
qemu_free (sw->name);
166+
g_free (sw->name);
167167
sw->name = NULL;
168168
}
169169
return err;
@@ -173,7 +173,7 @@ static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw)
173173
{
174174
glue (audio_pcm_sw_free_resources_, TYPE) (sw);
175175
if (sw->name) {
176-
qemu_free (sw->name);
176+
g_free (sw->name);
177177
sw->name = NULL;
178178
}
179179
}
@@ -201,7 +201,7 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
201201
glue (s->nb_hw_voices_, TYPE) += 1;
202202
glue (audio_pcm_hw_free_resources_ ,TYPE) (hw);
203203
glue (hw->pcm_ops->fini_, TYPE) (hw);
204-
qemu_free (hw);
204+
g_free (hw);
205205
*hwp = NULL;
206206
}
207207
}
@@ -300,7 +300,7 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)
300300
err1:
301301
glue (hw->pcm_ops->fini_, TYPE) (hw);
302302
err0:
303-
qemu_free (hw);
303+
g_free (hw);
304304
return NULL;
305305
}
306306

@@ -368,7 +368,7 @@ static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
368368
glue (audio_pcm_hw_del_sw_, TYPE) (sw);
369369
glue (audio_pcm_hw_gc_, TYPE) (&hw);
370370
err2:
371-
qemu_free (sw);
371+
g_free (sw);
372372
err1:
373373
return NULL;
374374
}
@@ -378,7 +378,7 @@ static void glue (audio_close_, TYPE) (SW *sw)
378378
glue (audio_pcm_sw_fini_, TYPE) (sw);
379379
glue (audio_pcm_hw_del_sw_, TYPE) (sw);
380380
glue (audio_pcm_hw_gc_, TYPE) (&sw->hw);
381-
qemu_free (sw);
381+
g_free (sw);
382382
}
383383

384384
void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw)

audio/esdaudio.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static int qesd_init_out (HWVoiceOut *hw, struct audsettings *as)
246246
esd->fd = -1;
247247

248248
fail1:
249-
qemu_free (esd->pcm_buf);
249+
g_free (esd->pcm_buf);
250250
esd->pcm_buf = NULL;
251251
return -1;
252252
}
@@ -270,7 +270,7 @@ static void qesd_fini_out (HWVoiceOut *hw)
270270

271271
audio_pt_fini (&esd->pt, AUDIO_FUNC);
272272

273-
qemu_free (esd->pcm_buf);
273+
g_free (esd->pcm_buf);
274274
esd->pcm_buf = NULL;
275275
}
276276

@@ -453,7 +453,7 @@ static int qesd_init_in (HWVoiceIn *hw, struct audsettings *as)
453453
esd->fd = -1;
454454

455455
fail1:
456-
qemu_free (esd->pcm_buf);
456+
g_free (esd->pcm_buf);
457457
esd->pcm_buf = NULL;
458458
return -1;
459459
}
@@ -477,7 +477,7 @@ static void qesd_fini_in (HWVoiceIn *hw)
477477

478478
audio_pt_fini (&esd->pt, AUDIO_FUNC);
479479

480-
qemu_free (esd->pcm_buf);
480+
g_free (esd->pcm_buf);
481481
esd->pcm_buf = NULL;
482482
}
483483

audio/mixeng.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void *st_rate_start (int inrate, int outrate)
326326

327327
void st_rate_stop (void *opaque)
328328
{
329-
qemu_free (opaque);
329+
g_free (opaque);
330330
}
331331

332332
void mixeng_clear (struct st_sample *buf, int len)

0 commit comments

Comments
 (0)