Skip to content

Commit aa8236d

Browse files
committed
qemu-malloc.c: Remove qemu-specific heap routines.
Remove all uses of qemu_malloc/malloc0/realloc/free/strdup/etc to use the equivalent GLib functions (g_malloc, g_free, ...) as per upstream. This also removes qemu-malloc.c since it's no longer required. Change-Id: I3c36a0396b73dd114b8da385b43f56a2e54dbb15
1 parent 1d1a2af commit aa8236d

File tree

146 files changed

+849
-953
lines changed

Some content is hidden

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

146 files changed

+849
-953
lines changed

Makefile.common

-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ CORE_MISC_SOURCES = \
429429
iohandler.c \
430430
ioport.c \
431431
qemu-char.c \
432-
qemu-malloc.c \
433432
readline.c \
434433
savevm.c \
435434
android/boot-properties.c \

aio-android.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ int qemu_aio_set_fd_handler(int fd,
7676
* releasing the walking_handlers lock.
7777
*/
7878
QLIST_REMOVE(node, node);
79-
qemu_free(node);
79+
g_free(node);
8080
}
8181
}
8282
} else {
8383
if (node == NULL) {
8484
/* Alloc and insert if it's not already there */
85-
node = qemu_mallocz(sizeof(AioHandler));
85+
node = g_malloc0(sizeof(AioHandler));
8686
node->fd = fd;
8787
QLIST_INSERT_HEAD(&aio_handlers, node, node);
8888
}
@@ -217,7 +217,7 @@ void qemu_aio_wait(void)
217217

218218
if (tmp->deleted) {
219219
QLIST_REMOVE(tmp, node);
220-
qemu_free(tmp);
220+
g_free(tmp);
221221
}
222222
}
223223

aio.c

+3-3
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

android/looper-qemu.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void qlooper_delIo(QLooper* looper, QLoopIo* io);
140140
static QLoopIo*
141141
qloopio_new(int fd, LoopIoFunc callback, void* opaque, QLooper* qlooper)
142142
{
143-
QLoopIo* io = qemu_malloc(sizeof(*io));
143+
QLoopIo* io = g_malloc(sizeof(*io));
144144

145145
io->fd = fd;
146146
io->user_callback = callback;
@@ -251,7 +251,7 @@ qloopio_free(void* impl)
251251
/* make QEMU forget about this fd */
252252
qemu_set_fd_handler(io->fd, NULL, NULL, NULL);
253253
io->fd = -1;
254-
qemu_free(io);
254+
g_free(io);
255255
}
256256

257257
static unsigned
@@ -400,13 +400,13 @@ qlooper_destroy(Looper* ll)
400400
qloopio_free(io);
401401

402402
qemu_bh_delete(looper->io_bh);
403-
qemu_free(looper);
403+
g_free(looper);
404404
}
405405

406406
Looper*
407407
looper_newCore(void)
408408
{
409-
QLooper* looper = qemu_mallocz(sizeof(*looper));
409+
QLooper* looper = g_malloc0(sizeof(*looper));
410410

411411
looper->io_list = NULL;
412412
looper->io_pending = NULL;

android/protocol/core-commands-impl.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ _alloc_cmd_param_buf(CoreCmdImpl* corecmd, uint32_t size)
8989
corecmd->cmd_param_buf = &corecmd->cmd_param[0];
9090
} else {
9191
// Expected request us too large to fit into preallocated buffer.
92-
corecmd->cmd_param_buf = qemu_malloc(size);
92+
corecmd->cmd_param_buf = g_malloc(size);
9393
}
9494
return corecmd->cmd_param_buf;
9595
}
@@ -100,7 +100,7 @@ static void
100100
_free_cmd_param_buf(CoreCmdImpl* corecmd)
101101
{
102102
if (corecmd->cmd_param_buf != &corecmd->cmd_param[0]) {
103-
qemu_free(corecmd->cmd_param_buf);
103+
g_free(corecmd->cmd_param_buf);
104104
corecmd->cmd_param_buf = &corecmd->cmd_param[0];
105105
}
106106
}
@@ -227,7 +227,7 @@ _coreCmdImpl_handle_command(CoreCmdImpl* corecmd,
227227
}
228228
// Allocate and initialize response data buffer.
229229
resp_data =
230-
(UICmdGetNetSpeedResp*)qemu_malloc(resp.resp_data_size);
230+
(UICmdGetNetSpeedResp*)g_malloc(resp.resp_data_size);
231231
resp_data->upload = netspeed->upload;
232232
resp_data->download = netspeed->download;
233233
strcpy(resp_data->name, netspeed->name);
@@ -240,7 +240,7 @@ _coreCmdImpl_handle_command(CoreCmdImpl* corecmd,
240240
}
241241
_coreCmdImpl_respond(corecmd, &resp, resp_data);
242242
if (resp_data != NULL) {
243-
qemu_free(resp_data);
243+
g_free(resp_data);
244244
}
245245
break;
246246
}
@@ -271,7 +271,7 @@ _coreCmdImpl_handle_command(CoreCmdImpl* corecmd,
271271
}
272272
// Allocate and initialize response data buffer.
273273
resp_data =
274-
(UICmdGetNetDelayResp*)qemu_malloc(resp.resp_data_size);
274+
(UICmdGetNetDelayResp*)g_malloc(resp.resp_data_size);
275275
resp_data->min_ms = netdelay->min_ms;
276276
resp_data->max_ms = netdelay->max_ms;
277277
strcpy(resp_data->name, netdelay->name);
@@ -284,7 +284,7 @@ _coreCmdImpl_handle_command(CoreCmdImpl* corecmd,
284284
}
285285
_coreCmdImpl_respond(corecmd, &resp, resp_data);
286286
if (resp_data != NULL) {
287-
qemu_free(resp_data);
287+
g_free(resp_data);
288288
}
289289
break;
290290
}
@@ -303,7 +303,7 @@ _coreCmdImpl_handle_command(CoreCmdImpl* corecmd,
303303
}
304304
_coreCmdImpl_respond(corecmd, &resp, filepath);
305305
if (filepath != NULL) {
306-
qemu_free(filepath);
306+
g_free(filepath);
307307
}
308308
break;
309309
}

android/protocol/core-commands-qemu.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ corecmd_get_qemu_path(int type,
9797
}
9898
strncpy(path, filepath, path_buf_size);
9999
path[path_buf_size - 1] = '\0';
100-
qemu_free(filepath);
100+
g_free(filepath);
101101
return 0;
102102
}
103103

android/protocol/ui-commands-proxy.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ _uiCmdProxy_brightness_change_callback(void* opaque,
149149
const size_t cmd_size = sizeof(UICmdChangeDispBrightness) + strlen(light) + 1;
150150
// Allocate and initialize parameters.
151151
UICmdChangeDispBrightness* cmd =
152-
(UICmdChangeDispBrightness*)qemu_malloc(cmd_size);
152+
(UICmdChangeDispBrightness*)g_malloc(cmd_size);
153153
cmd->brightness = brightness;
154154
strcpy(cmd->light, light);
155155
// Send the command.
156156
_uiCmdProxy_send_command(AUICMD_CHANGE_DISP_BRIGHTNESS, cmd, cmd_size);
157-
qemu_free(cmd);
157+
g_free(cmd);
158158
}
159159

160160
int

android/shaper.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ queued_packet_create( const void* data,
7272
if (do_copy)
7373
packet_size += size;
7474

75-
packet = qemu_malloc(packet_size);
75+
packet = g_malloc(packet_size);
7676
packet->next = NULL;
7777
packet->expiration = 0;
7878
packet->size = (size_t)size;
@@ -91,7 +91,7 @@ static void
9191
queued_packet_free( QueuedPacket packet )
9292
{
9393
if (packet) {
94-
qemu_free( packet );
94+
g_free( packet );
9595
}
9696
}
9797

@@ -126,7 +126,7 @@ netshaper_destroy( NetShaper shaper )
126126
qemu_del_timer(shaper->timer);
127127
qemu_free_timer(shaper->timer);
128128
shaper->timer = NULL;
129-
qemu_free(shaper);
129+
g_free(shaper);
130130
}
131131
}
132132

@@ -162,7 +162,7 @@ NetShaper
162162
netshaper_create( int do_copy,
163163
NetShaperSendFunc send_func )
164164
{
165-
NetShaper shaper = qemu_malloc(sizeof(*shaper));
165+
NetShaper shaper = g_malloc(sizeof(*shaper));
166166

167167
shaper->active = 0;
168168
shaper->packets = NULL;
@@ -188,7 +188,7 @@ netshaper_set_rate( NetShaper shaper,
188188
QueuedPacket packet = shaper->packets;
189189
shaper->packets = packet->next;
190190
shaper->send_func(packet->data, packet->size, packet->opaque);
191-
qemu_free(packet);
191+
g_free(packet);
192192
shaper->num_packets = 0;
193193
}
194194

@@ -311,7 +311,7 @@ session_free( Session session )
311311
queued_packet_free(session->packet);
312312
session->packet = NULL;
313313
}
314-
qemu_free( session );
314+
g_free( session );
315315
}
316316
}
317317

@@ -459,7 +459,7 @@ netdelay_expires( NetDelay delay )
459459
NetDelay
460460
netdelay_create( NetShaperSendFunc send_func )
461461
{
462-
NetDelay delay = qemu_malloc(sizeof(*delay));
462+
NetDelay delay = g_malloc(sizeof(*delay));
463463

464464
delay->sessions = NULL;
465465
delay->num_sessions = 0;
@@ -547,7 +547,7 @@ netdelay_send_aux( NetDelay delay, const void* data, size_t size, void* opaqu
547547
latency += rand() % range;
548548

549549
//fprintf(stderr, "NetDelay:RST: delay creation for %s\n", session_to_string(info) );
550-
session = qemu_malloc( sizeof(*session) );
550+
session = g_malloc( sizeof(*session) );
551551

552552
session->next = delay->sessions;
553553
delay->sessions = session;
@@ -584,7 +584,7 @@ netdelay_destroy( NetDelay delay )
584584
delay->num_sessions -= 1;
585585
}
586586
delay->active = 0;
587-
qemu_free( delay );
587+
g_free( delay );
588588
}
589589
}
590590

arch_init.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static void sort_ram_list(void)
236236
QLIST_FOREACH(block, &ram_list.blocks, next) {
237237
++n;
238238
}
239-
blocks = qemu_malloc(n * sizeof *blocks);
239+
blocks = g_malloc(n * sizeof *blocks);
240240
n = 0;
241241
QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
242242
blocks[n++] = block;
@@ -246,7 +246,7 @@ static void sort_ram_list(void)
246246
while (--n >= 0) {
247247
QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next);
248248
}
249-
qemu_free(blocks);
249+
g_free(blocks);
250250
}
251251

252252
int ram_save_live(QEMUFile *f, int stage, void *opaque)

async.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static struct AsyncContext *async_context = &(struct AsyncContext) { 0 };
6464
*/
6565
void async_context_push(void)
6666
{
67-
struct AsyncContext *new = qemu_mallocz(sizeof(*new));
67+
struct AsyncContext *new = g_malloc0(sizeof(*new));
6868
new->parent = async_context;
6969
new->id = async_context->id + 1;
7070
async_context = new;
@@ -75,7 +75,7 @@ static void bh_run_aio_completions(void *opaque)
7575
{
7676
QEMUBH **bh = opaque;
7777
qemu_bh_delete(*bh);
78-
qemu_free(bh);
78+
g_free(bh);
7979
qemu_aio_process_queue();
8080
}
8181
/*
@@ -92,14 +92,14 @@ void async_context_pop(void)
9292

9393
/* Switch back to the parent context */
9494
async_context = async_context->parent;
95-
qemu_free(old);
95+
g_free(old);
9696

9797
if (async_context == NULL) {
9898
abort();
9999
}
100100

101101
/* Schedule BH to run any queued AIO completions as soon as possible */
102-
bh = qemu_malloc(sizeof(*bh));
102+
bh = g_malloc(sizeof(*bh));
103103
*bh = qemu_bh_new(bh_run_aio_completions, bh);
104104
qemu_bh_schedule(*bh);
105105
}
@@ -127,7 +127,7 @@ struct QEMUBH {
127127
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
128128
{
129129
QEMUBH *bh;
130-
bh = qemu_mallocz(sizeof(QEMUBH));
130+
bh = g_malloc0(sizeof(QEMUBH));
131131
bh->cb = cb;
132132
bh->opaque = opaque;
133133
bh->next = async_context->first_bh;
@@ -157,7 +157,7 @@ int qemu_bh_poll(void)
157157
bh = *bhp;
158158
if (bh->deleted) {
159159
*bhp = bh->next;
160-
qemu_free(bh);
160+
g_free(bh);
161161
} else
162162
bhp = &bh->next;
163163
}

audio/alsaaudio.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static void alsa_fini_poll (struct pollhlp *hlp)
208208
for (i = 0; i < hlp->count; ++i) {
209209
qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);
210210
}
211-
qemu_free (pfds);
211+
g_free (pfds);
212212
}
213213
hlp->pfds = NULL;
214214
hlp->count = 0;
@@ -332,7 +332,7 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)
332332
if (err < 0) {
333333
alsa_logerr (err, "Could not initialize poll mode\n"
334334
"Could not obtain poll descriptors\n");
335-
qemu_free (pfds);
335+
g_free (pfds);
336336
return -1;
337337
}
338338

@@ -360,7 +360,7 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)
360360
while (i--) {
361361
qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);
362362
}
363-
qemu_free (pfds);
363+
g_free (pfds);
364364
return -1;
365365
}
366366
}
@@ -869,7 +869,7 @@ static void alsa_fini_out (HWVoiceOut *hw)
869869
alsa_anal_close (&alsa->handle, &alsa->pollhlp);
870870

871871
if (alsa->pcm_buf) {
872-
qemu_free (alsa->pcm_buf);
872+
g_free (alsa->pcm_buf);
873873
alsa->pcm_buf = NULL;
874874
}
875875
}
@@ -1039,7 +1039,7 @@ static void alsa_fini_in (HWVoiceIn *hw)
10391039
alsa_anal_close (&alsa->handle, &alsa->pollhlp);
10401040

10411041
if (alsa->pcm_buf) {
1042-
qemu_free (alsa->pcm_buf);
1042+
g_free (alsa->pcm_buf);
10431043
alsa->pcm_buf = NULL;
10441044
}
10451045
}

0 commit comments

Comments
 (0)