mirror of
https://git.proxmox.com/git/qemu
synced 2025-08-14 10:31:18 +00:00
qemu-char: Plug memory leak on qemu_chr_open_pty() error path
Spotted by Coverity. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
1299c63168
commit
a4e2604852
21
qemu-char.c
21
qemu-char.c
@ -985,7 +985,7 @@ static int qemu_chr_open_pty(QemuOpts *opts, CharDriverState **_chr)
|
|||||||
CharDriverState *chr;
|
CharDriverState *chr;
|
||||||
PtyCharDriver *s;
|
PtyCharDriver *s;
|
||||||
struct termios tty;
|
struct termios tty;
|
||||||
int slave_fd, len;
|
int master_fd, slave_fd, len;
|
||||||
#if defined(__OpenBSD__) || defined(__DragonFly__)
|
#if defined(__OpenBSD__) || defined(__DragonFly__)
|
||||||
char pty_name[PATH_MAX];
|
char pty_name[PATH_MAX];
|
||||||
#define q_ptsname(x) pty_name
|
#define q_ptsname(x) pty_name
|
||||||
@ -994,10 +994,7 @@ static int qemu_chr_open_pty(QemuOpts *opts, CharDriverState **_chr)
|
|||||||
#define q_ptsname(x) ptsname(x)
|
#define q_ptsname(x) ptsname(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
chr = g_malloc0(sizeof(CharDriverState));
|
if (openpty(&master_fd, &slave_fd, pty_name, NULL, NULL) < 0) {
|
||||||
s = g_malloc0(sizeof(PtyCharDriver));
|
|
||||||
|
|
||||||
if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) {
|
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1007,17 +1004,21 @@ static int qemu_chr_open_pty(QemuOpts *opts, CharDriverState **_chr)
|
|||||||
tcsetattr(slave_fd, TCSAFLUSH, &tty);
|
tcsetattr(slave_fd, TCSAFLUSH, &tty);
|
||||||
close(slave_fd);
|
close(slave_fd);
|
||||||
|
|
||||||
len = strlen(q_ptsname(s->fd)) + 5;
|
chr = g_malloc0(sizeof(CharDriverState));
|
||||||
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));
|
|
||||||
|
|
||||||
|
len = strlen(q_ptsname(master_fd)) + 5;
|
||||||
|
chr->filename = g_malloc(len);
|
||||||
|
snprintf(chr->filename, len, "pty:%s", q_ptsname(master_fd));
|
||||||
|
qemu_opt_set(opts, "path", q_ptsname(master_fd));
|
||||||
|
fprintf(stderr, "char device redirected to %s\n", q_ptsname(master_fd));
|
||||||
|
|
||||||
|
s = g_malloc0(sizeof(PtyCharDriver));
|
||||||
chr->opaque = s;
|
chr->opaque = s;
|
||||||
chr->chr_write = pty_chr_write;
|
chr->chr_write = pty_chr_write;
|
||||||
chr->chr_update_read_handler = pty_chr_update_read_handler;
|
chr->chr_update_read_handler = pty_chr_update_read_handler;
|
||||||
chr->chr_close = pty_chr_close;
|
chr->chr_close = pty_chr_close;
|
||||||
|
|
||||||
|
s->fd = master_fd;
|
||||||
s->timer = qemu_new_timer_ms(rt_clock, pty_chr_timer, chr);
|
s->timer = qemu_new_timer_ms(rt_clock, pty_chr_timer, chr);
|
||||||
|
|
||||||
*_chr = chr;
|
*_chr = chr;
|
||||||
|
Loading…
Reference in New Issue
Block a user