mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 20:33:54 -06:00
Use glib memory allocation and free functions
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
14015304b6
commit
7267c0947d
357 changed files with 1672 additions and 1674 deletions
84
qemu-char.c
84
qemu-char.c
|
@ -228,7 +228,7 @@ static int qemu_chr_open_null(QemuOpts *opts, CharDriverState **_chr)
|
|||
{
|
||||
CharDriverState *chr;
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
chr->chr_write = null_chr_write;
|
||||
|
||||
*_chr= chr;
|
||||
|
@ -477,8 +477,8 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
|
|||
CharDriverState *chr;
|
||||
MuxDriver *d;
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
d = qemu_mallocz(sizeof(MuxDriver));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
d = g_malloc0(sizeof(MuxDriver));
|
||||
|
||||
chr->opaque = d;
|
||||
d->drv = drv;
|
||||
|
@ -617,7 +617,7 @@ static void fd_chr_close(struct CharDriverState *chr)
|
|||
}
|
||||
}
|
||||
|
||||
qemu_free(s);
|
||||
g_free(s);
|
||||
qemu_chr_event(chr, CHR_EVENT_CLOSED);
|
||||
}
|
||||
|
||||
|
@ -627,8 +627,8 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
|
|||
CharDriverState *chr;
|
||||
FDCharDriver *s;
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
s = qemu_mallocz(sizeof(FDCharDriver));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
s = g_malloc0(sizeof(FDCharDriver));
|
||||
s->fd_in = fd_in;
|
||||
s->fd_out = fd_out;
|
||||
chr->opaque = s;
|
||||
|
@ -981,7 +981,7 @@ static void pty_chr_close(struct CharDriverState *chr)
|
|||
close(s->fd);
|
||||
qemu_del_timer(s->timer);
|
||||
qemu_free_timer(s->timer);
|
||||
qemu_free(s);
|
||||
g_free(s);
|
||||
qemu_chr_event(chr, CHR_EVENT_CLOSED);
|
||||
}
|
||||
|
||||
|
@ -999,8 +999,8 @@ static int qemu_chr_open_pty(QemuOpts *opts, CharDriverState **_chr)
|
|||
#define q_ptsname(x) ptsname(x)
|
||||
#endif
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
s = qemu_mallocz(sizeof(PtyCharDriver));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
s = g_malloc0(sizeof(PtyCharDriver));
|
||||
|
||||
if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) {
|
||||
return -errno;
|
||||
|
@ -1013,7 +1013,7 @@ static int qemu_chr_open_pty(QemuOpts *opts, CharDriverState **_chr)
|
|||
close(slave_fd);
|
||||
|
||||
len = strlen(q_ptsname(s->fd)) + 5;
|
||||
chr->filename = qemu_malloc(len);
|
||||
chr->filename = g_malloc(len);
|
||||
snprintf(chr->filename, len, "pty:%s", q_ptsname(s->fd));
|
||||
qemu_opt_set(opts, "path", q_ptsname(s->fd));
|
||||
fprintf(stderr, "char device redirected to %s\n", q_ptsname(s->fd));
|
||||
|
@ -1358,7 +1358,7 @@ static void pp_close(CharDriverState *chr)
|
|||
pp_hw_mode(drv, IEEE1284_MODE_COMPAT);
|
||||
ioctl(fd, PPRELEASE);
|
||||
close(fd);
|
||||
qemu_free(drv);
|
||||
g_free(drv);
|
||||
qemu_chr_event(chr, CHR_EVENT_CLOSED);
|
||||
}
|
||||
|
||||
|
@ -1379,11 +1379,11 @@ static int qemu_chr_open_pp(QemuOpts *opts, CharDriverState **_chr)
|
|||
return -errno;
|
||||
}
|
||||
|
||||
drv = qemu_mallocz(sizeof(ParallelCharDriver));
|
||||
drv = g_malloc0(sizeof(ParallelCharDriver));
|
||||
drv->fd = fd;
|
||||
drv->mode = IEEE1284_MODE_COMPAT;
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
chr->chr_write = null_chr_write;
|
||||
chr->chr_ioctl = pp_ioctl;
|
||||
chr->chr_close = pp_close;
|
||||
|
@ -1445,7 +1445,7 @@ static int qemu_chr_open_pp(QemuOpts *opts, CharDriverState **_chr)
|
|||
return -errno;
|
||||
}
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
chr->opaque = (void *)(intptr_t)fd;
|
||||
chr->chr_write = null_chr_write;
|
||||
chr->chr_ioctl = pp_ioctl;
|
||||
|
@ -1663,8 +1663,8 @@ static int qemu_chr_open_win(QemuOpts *opts, CharDriverState **_chr)
|
|||
CharDriverState *chr;
|
||||
WinCharState *s;
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
s = qemu_mallocz(sizeof(WinCharState));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
s = g_malloc0(sizeof(WinCharState));
|
||||
chr->opaque = s;
|
||||
chr->chr_write = win_chr_write;
|
||||
chr->chr_close = win_chr_close;
|
||||
|
@ -1765,8 +1765,8 @@ static int qemu_chr_open_win_pipe(QemuOpts *opts, CharDriverState **_chr)
|
|||
CharDriverState *chr;
|
||||
WinCharState *s;
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
s = qemu_mallocz(sizeof(WinCharState));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
s = g_malloc0(sizeof(WinCharState));
|
||||
chr->opaque = s;
|
||||
chr->chr_write = win_chr_write;
|
||||
chr->chr_close = win_chr_close;
|
||||
|
@ -1787,8 +1787,8 @@ static int qemu_chr_open_win_file(HANDLE fd_out, CharDriverState **pchr)
|
|||
CharDriverState *chr;
|
||||
WinCharState *s;
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
s = qemu_mallocz(sizeof(WinCharState));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
s = g_malloc0(sizeof(WinCharState));
|
||||
s->hcom = fd_out;
|
||||
chr->opaque = s;
|
||||
chr->chr_write = win_chr_write;
|
||||
|
@ -1890,7 +1890,7 @@ static void udp_chr_close(CharDriverState *chr)
|
|||
qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
|
||||
closesocket(s->fd);
|
||||
}
|
||||
qemu_free(s);
|
||||
g_free(s);
|
||||
qemu_chr_event(chr, CHR_EVENT_CLOSED);
|
||||
}
|
||||
|
||||
|
@ -1901,8 +1901,8 @@ static int qemu_chr_open_udp(QemuOpts *opts, CharDriverState **_chr)
|
|||
int fd = -1;
|
||||
int ret;
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
s = qemu_mallocz(sizeof(NetCharDriver));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
s = g_malloc0(sizeof(NetCharDriver));
|
||||
|
||||
fd = inet_dgram_opts(opts);
|
||||
if (fd < 0) {
|
||||
|
@ -1923,8 +1923,8 @@ static int qemu_chr_open_udp(QemuOpts *opts, CharDriverState **_chr)
|
|||
return 0;
|
||||
|
||||
return_err:
|
||||
qemu_free(chr);
|
||||
qemu_free(s);
|
||||
g_free(chr);
|
||||
g_free(s);
|
||||
if (fd >= 0) {
|
||||
closesocket(fd);
|
||||
}
|
||||
|
@ -2215,7 +2215,7 @@ static void tcp_chr_close(CharDriverState *chr)
|
|||
qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
|
||||
closesocket(s->listen_fd);
|
||||
}
|
||||
qemu_free(s);
|
||||
g_free(s);
|
||||
qemu_chr_event(chr, CHR_EVENT_CLOSED);
|
||||
}
|
||||
|
||||
|
@ -2239,8 +2239,8 @@ static int qemu_chr_open_socket(QemuOpts *opts, CharDriverState **_chr)
|
|||
if (!is_listen)
|
||||
is_waitconnect = 0;
|
||||
|
||||
chr = qemu_mallocz(sizeof(CharDriverState));
|
||||
s = qemu_mallocz(sizeof(TCPCharDriver));
|
||||
chr = g_malloc0(sizeof(CharDriverState));
|
||||
s = g_malloc0(sizeof(TCPCharDriver));
|
||||
|
||||
if (is_unix) {
|
||||
if (is_listen) {
|
||||
|
@ -2290,7 +2290,7 @@ static int qemu_chr_open_socket(QemuOpts *opts, CharDriverState **_chr)
|
|||
}
|
||||
|
||||
/* for "info chardev" monitor command */
|
||||
chr->filename = qemu_malloc(256);
|
||||
chr->filename = g_malloc(256);
|
||||
if (is_unix) {
|
||||
snprintf(chr->filename, 256, "unix:%s%s",
|
||||
qemu_opt_get(opts, "path"),
|
||||
|
@ -2318,8 +2318,8 @@ static int qemu_chr_open_socket(QemuOpts *opts, CharDriverState **_chr)
|
|||
fail:
|
||||
if (fd >= 0)
|
||||
closesocket(fd);
|
||||
qemu_free(s);
|
||||
qemu_free(chr);
|
||||
g_free(s);
|
||||
g_free(chr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -2341,7 +2341,7 @@ static int mem_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
|
|||
/* grow outbuf */
|
||||
d->outbuf_capacity += len;
|
||||
d->outbuf_capacity *= 2;
|
||||
d->outbuf = qemu_realloc(d->outbuf, d->outbuf_capacity);
|
||||
d->outbuf = g_realloc(d->outbuf, d->outbuf_capacity);
|
||||
}
|
||||
|
||||
memcpy(d->outbuf + d->outbuf_size, buf, len);
|
||||
|
@ -2354,10 +2354,10 @@ void qemu_chr_init_mem(CharDriverState *chr)
|
|||
{
|
||||
MemoryDriver *d;
|
||||
|
||||
d = qemu_malloc(sizeof(*d));
|
||||
d = g_malloc(sizeof(*d));
|
||||
d->outbuf_size = 0;
|
||||
d->outbuf_capacity = 4096;
|
||||
d->outbuf = qemu_mallocz(d->outbuf_capacity);
|
||||
d->outbuf = g_malloc0(d->outbuf_capacity);
|
||||
|
||||
memset(chr, 0, sizeof(*chr));
|
||||
chr->opaque = d;
|
||||
|
@ -2375,8 +2375,8 @@ void qemu_chr_close_mem(CharDriverState *chr)
|
|||
{
|
||||
MemoryDriver *d = chr->opaque;
|
||||
|
||||
qemu_free(d->outbuf);
|
||||
qemu_free(chr->opaque);
|
||||
g_free(d->outbuf);
|
||||
g_free(chr->opaque);
|
||||
chr->opaque = NULL;
|
||||
chr->chr_write = NULL;
|
||||
}
|
||||
|
@ -2583,14 +2583,14 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
|
|||
}
|
||||
|
||||
if (!chr->filename)
|
||||
chr->filename = qemu_strdup(qemu_opt_get(opts, "backend"));
|
||||
chr->filename = g_strdup(qemu_opt_get(opts, "backend"));
|
||||
chr->init = init;
|
||||
QTAILQ_INSERT_TAIL(&chardevs, chr, next);
|
||||
|
||||
if (qemu_opt_get_bool(opts, "mux", 0)) {
|
||||
CharDriverState *base = chr;
|
||||
int len = strlen(qemu_opts_id(opts)) + 6;
|
||||
base->label = qemu_malloc(len);
|
||||
base->label = g_malloc(len);
|
||||
snprintf(base->label, len, "%s-base", qemu_opts_id(opts));
|
||||
chr = qemu_chr_open_mux(base);
|
||||
chr->filename = base->filename;
|
||||
|
@ -2599,7 +2599,7 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
|
|||
} else {
|
||||
chr->avail_connections = 1;
|
||||
}
|
||||
chr->label = qemu_strdup(qemu_opts_id(opts));
|
||||
chr->label = g_strdup(qemu_opts_id(opts));
|
||||
return chr;
|
||||
}
|
||||
|
||||
|
@ -2651,9 +2651,9 @@ void qemu_chr_close(CharDriverState *chr)
|
|||
QTAILQ_REMOVE(&chardevs, chr, next);
|
||||
if (chr->chr_close)
|
||||
chr->chr_close(chr);
|
||||
qemu_free(chr->filename);
|
||||
qemu_free(chr->label);
|
||||
qemu_free(chr);
|
||||
g_free(chr->filename);
|
||||
g_free(chr->label);
|
||||
g_free(chr);
|
||||
}
|
||||
|
||||
static void qemu_chr_qlist_iter(QObject *obj, void *opaque)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue