aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-02-05 22:06:18 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-02-05 22:06:18 +0000
commit1eec614b36390be66430ed6dd0ce47a6f2f0ae1a (patch)
treefa9174028d54ea9a531a77d05996688fc704fadd
parent0d0266a53b4c80ab08c093c36bb3a7bbb29cc3e5 (diff)
toplevel: remove error handling from qemu_malloc() callers (Avi Kivity)
Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6531 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--aio.c2
-rw-r--r--buffered_file.c2
-rw-r--r--console.c23
-rw-r--r--cris-dis.c26
-rw-r--r--curses.c2
-rw-r--r--device_tree.c4
-rw-r--r--exec.c25
-rw-r--r--gdbstub.c8
-rw-r--r--keymaps.c10
-rw-r--r--kvm-all.c7
-rw-r--r--loader.c4
-rw-r--r--migration-exec.c5
-rw-r--r--migration-tcp.c2
-rw-r--r--monitor.c4
-rw-r--r--net.c14
-rw-r--r--qemu-char.c59
-rw-r--r--qemu-nbd.c2
-rw-r--r--qemu-tool.c6
-rw-r--r--readline.c2
-rw-r--r--savevm.c19
-rw-r--r--sdl.c2
-rw-r--r--usb-bsd.c2
-rw-r--r--usb-linux.c24
-rw-r--r--vl.c16
-rw-r--r--vnc.c9
25 files changed, 25 insertions, 254 deletions
diff --git a/aio.c b/aio.c
index 70d3cdc5aa..200320c979 100644
--- a/aio.c
+++ b/aio.c
@@ -79,8 +79,6 @@ int qemu_aio_set_fd_handler(int fd,
if (node == NULL) {
/* Alloc and insert if it's not already there */
node = qemu_mallocz(sizeof(AioHandler));
- if (node == NULL)
- return -ENOMEM;
node->fd = fd;
LIST_INSERT_HEAD(&aio_handlers, node, node);
}
diff --git a/buffered_file.c b/buffered_file.c
index be5baea656..ec4f6641cc 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -228,8 +228,6 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,
QEMUFileBuffered *s;
s = qemu_mallocz(sizeof(*s));
- if (s == NULL)
- return NULL;
s->opaque = opaque;
s->xfer_limit = bytes_per_sec / 10;
diff --git a/console.c b/console.c
index 68ac970654..3f2794e16d 100644
--- a/console.c
+++ b/console.c
@@ -1246,9 +1246,6 @@ static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
if (nb_consoles >= MAX_CONSOLES)
return NULL;
s = qemu_mallocz(sizeof(TextConsole));
- if (!s) {
- return NULL;
- }
if (!active_console || ((active_console->console_type != GRAPHIC_CONSOLE) &&
(console_type == GRAPHIC_CONSOLE))) {
active_console = s;
@@ -1280,8 +1277,6 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,
DisplayState *ds;
ds = (DisplayState *) qemu_mallocz(sizeof(DisplayState));
- if (ds == NULL)
- return NULL;
ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
s = new_console(ds, GRAPHIC_CONSOLE);
@@ -1402,8 +1397,6 @@ CharDriverState *text_console_init(const char *p)
CharDriverState *chr;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- return NULL;
if (n_text_consoles == 128) {
fprintf(stderr, "Too many text consoles\n");
@@ -1562,10 +1555,6 @@ PixelFormat qemu_default_pixelformat(int bpp)
DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int linesize)
{
DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
- if (surface == NULL) {
- fprintf(stderr, "qemu_create_displaysurface: malloc failed\n");
- exit(1);
- }
surface->width = width;
surface->height = height;
@@ -1577,10 +1566,6 @@ DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int l
surface->flags = QEMU_ALLOCATED_FLAG;
#endif
surface->data = (uint8_t*) qemu_mallocz(surface->linesize * surface->height);
- if (surface->data == NULL) {
- fprintf(stderr, "qemu_create_displaysurface: malloc failed\n");
- exit(1);
- }
return surface;
}
@@ -1596,10 +1581,6 @@ DisplaySurface* qemu_resize_displaysurface(DisplaySurface *surface,
surface->data = (uint8_t*) qemu_realloc(surface->data, surface->linesize * surface->height);
else
surface->data = (uint8_t*) qemu_malloc(surface->linesize * surface->height);
- if (surface->data == NULL) {
- fprintf(stderr, "qemu_resize_displaysurface: malloc failed\n");
- exit(1);
- }
#ifdef WORDS_BIGENDIAN
surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG;
#else
@@ -1613,10 +1594,6 @@ DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
int linesize, uint8_t *data)
{
DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
- if (surface == NULL) {
- fprintf(stderr, "qemu_create_displaysurface_from: malloc failed\n");
- exit(1);
- }
surface->width = width;
surface->height = height;
diff --git a/cris-dis.c b/cris-dis.c
index 0781b0886b..ba6990758c 100644
--- a/cris-dis.c
+++ b/cris-dis.c
@@ -26,6 +26,8 @@
//#include "libiberty.h"
+void *qemu_malloc(size_t len); /* can't include qemu-common.h here */
+
#define FALSE 0
#define TRUE 1
#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
@@ -1401,44 +1403,32 @@ get_opcode_entry (unsigned int insn,
/* Allocate and clear the opcode-table. */
if (opc_table == NULL)
{
- opc_table = malloc (65536 * sizeof (opc_table[0]));
- if (opc_table == NULL)
- return NULL;
+ opc_table = qemu_malloc (65536 * sizeof (opc_table[0]));
memset (opc_table, 0, 65536 * sizeof (const struct cris_opcode *));
dip_prefixes
- = malloc (65536 * sizeof (const struct cris_opcode **));
- if (dip_prefixes == NULL)
- return NULL;
+ = qemu_malloc (65536 * sizeof (const struct cris_opcode **));
memset (dip_prefixes, 0, 65536 * sizeof (dip_prefixes[0]));
bdapq_m1_prefixes
- = malloc (65536 * sizeof (const struct cris_opcode **));
- if (bdapq_m1_prefixes == NULL)
- return NULL;
+ = qemu_malloc (65536 * sizeof (const struct cris_opcode **));
memset (bdapq_m1_prefixes, 0, 65536 * sizeof (bdapq_m1_prefixes[0]));
bdapq_m2_prefixes
- = malloc (65536 * sizeof (const struct cris_opcode **));
- if (bdapq_m2_prefixes == NULL)
- return NULL;
+ = qemu_malloc (65536 * sizeof (const struct cris_opcode **));
memset (bdapq_m2_prefixes, 0, 65536 * sizeof (bdapq_m2_prefixes[0]));
bdapq_m4_prefixes
- = malloc (65536 * sizeof (const struct cris_opcode **));
- if (bdapq_m4_prefixes == NULL)
- return NULL;
+ = qemu_malloc (65536 * sizeof (const struct cris_opcode **));
memset (bdapq_m4_prefixes, 0, 65536 * sizeof (bdapq_m4_prefixes[0]));
rest_prefixes
- = malloc (65536 * sizeof (const struct cris_opcode **));
- if (rest_prefixes == NULL)
- return NULL;
+ = qemu_malloc (65536 * sizeof (const struct cris_opcode **));
memset (rest_prefixes, 0, 65536 * sizeof (rest_prefixes[0]));
}
diff --git a/curses.c b/curses.c
index 97ab412632..d699b5e505 100644
--- a/curses.c
+++ b/curses.c
@@ -361,8 +361,6 @@ void curses_display_init(DisplayState *ds, int full_screen)
#endif
dcl = (DisplayChangeListener *) qemu_mallocz(sizeof(DisplayChangeListener));
- if (!dcl)
- exit(1);
dcl->dpy_update = curses_update;
dcl->dpy_resize = curses_resize;
dcl->dpy_refresh = curses_refresh;
diff --git a/device_tree.c b/device_tree.c
index 22386829de..4fc078159b 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -43,10 +43,6 @@ void *load_device_tree(const char *filename_path, void *load_addr)
/* First allocate space in qemu for device tree */
dt_file = qemu_mallocz(dt_file_size);
- if (dt_file == NULL) {
- printf("Unable to allocate memory in qemu for device tree\n");
- goto fail;
- }
dt_file_load_size = load_image(filename_path, dt_file);
diff --git a/exec.c b/exec.c
index 302da34f04..9852bdcd31 100644
--- a/exec.c
+++ b/exec.c
@@ -476,10 +476,6 @@ static void code_gen_alloc(unsigned long tb_size)
}
#else
code_gen_buffer = qemu_malloc(code_gen_buffer_size);
- if (!code_gen_buffer) {
- fprintf(stderr, "Could not allocate dynamic translator buffer\n");
- exit(1);
- }
map_exec(code_gen_buffer, code_gen_buffer_size);
#endif
#endif /* !USE_STATIC_CODE_GEN_BUFFER */
@@ -825,8 +821,6 @@ static void build_page_bitmap(PageDesc *p)
TranslationBlock *tb;
p->code_bitmap = qemu_mallocz(TARGET_PAGE_SIZE / 8);
- if (!p->code_bitmap)
- return;
tb = p->first_tb;
while (tb != NULL) {
@@ -1318,8 +1312,6 @@ int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len,
return -EINVAL;
}
wp = qemu_malloc(sizeof(*wp));
- if (!wp)
- return -ENOMEM;
wp->vaddr = addr;
wp->len_mask = len_mask;
@@ -1384,8 +1376,6 @@ int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags,
CPUBreakpoint *bp;
bp = qemu_malloc(sizeof(*bp));
- if (!bp)
- return -ENOMEM;
bp->pc = pc;
bp->flags = flags;
@@ -2795,17 +2785,16 @@ static void *subpage_init (target_phys_addr_t base, ram_addr_t *phys,
int subpage_memory;
mmio = qemu_mallocz(sizeof(subpage_t));
- if (mmio != NULL) {
- mmio->base = base;
- subpage_memory = cpu_register_io_memory(0, subpage_read, subpage_write, mmio);
+
+ mmio->base = base;
+ subpage_memory = cpu_register_io_memory(0, subpage_read, subpage_write, mmio);
#if defined(DEBUG_SUBPAGE)
- printf("%s: %p base " TARGET_FMT_plx " len %08x %d\n", __func__,
- mmio, base, TARGET_PAGE_SIZE, subpage_memory);
+ printf("%s: %p base " TARGET_FMT_plx " len %08x %d\n", __func__,
+ mmio, base, TARGET_PAGE_SIZE, subpage_memory);
#endif
- *phys = subpage_memory | IO_MEM_SUBPAGE;
- subpage_register(mmio, 0, TARGET_PAGE_SIZE - 1, orig_memory,
+ *phys = subpage_memory | IO_MEM_SUBPAGE;
+ subpage_register(mmio, 0, TARGET_PAGE_SIZE - 1, orig_memory,
region_offset);
- }
return mmio;
}
diff --git a/gdbstub.c b/gdbstub.c
index b4b8292dba..239f2e0a0e 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2189,11 +2189,6 @@ static void gdb_accept(void)
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
s = qemu_mallocz(sizeof(GDBState));
- if (!s) {
- errno = ENOMEM;
- perror("accept");
- return;
- }
memset (s, 0, sizeof (GDBState));
s->c_cpu = first_cpu;
@@ -2311,9 +2306,6 @@ int gdbserver_start(const char *port)
return -1;
s = qemu_mallocz(sizeof(GDBState));
- if (!s) {
- return -1;
- }
s->c_cpu = first_cpu;
s->g_cpu = first_cpu;
s->chr = chr;
diff --git a/keymaps.c b/keymaps.c
index 38e50f0c07..216e37831b 100644
--- a/keymaps.c
+++ b/keymaps.c
@@ -67,11 +67,9 @@ static void add_to_key_range(struct key_range **krp, int code) {
}
if (kr == NULL) {
kr = qemu_mallocz(sizeof(*kr));
- if (kr) {
- kr->start = kr->end = code;
- kr->next = *krp;
- *krp = kr;
- }
+ kr->start = kr->end = code;
+ kr->next = *krp;
+ *krp = kr;
}
}
@@ -88,8 +86,6 @@ static kbd_layout_t *parse_keyboard_layout(const char *language,
if (!k)
k = qemu_mallocz(sizeof(kbd_layout_t));
- if (!k)
- return 0;
if (!(f = fopen(file_name, "r"))) {
fprintf(stderr,
"Could not read keymap file: '%s'\n", file_name);
diff --git a/kvm-all.c b/kvm-all.c
index 9fb295ce63..0b1742709b 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -220,11 +220,6 @@ void kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, target_phys_a
alloc_size = mem->memory_size >> TARGET_PAGE_BITS / sizeof(d.dirty_bitmap);
d.dirty_bitmap = qemu_mallocz(alloc_size);
- if (d.dirty_bitmap == NULL) {
- dprintf("Could not allocate dirty bitmap\n");
- return;
- }
-
d.slot = mem->slot;
dprintf("slot %d, phys_addr %llx, uaddr: %llx\n",
d.slot, mem->start_addr, mem->phys_offset);
@@ -295,8 +290,6 @@ int kvm_init(int smp_cpus)
return -EINVAL;
s = qemu_mallocz(sizeof(KVMState));
- if (s == NULL)
- return -ENOMEM;
for (i = 0; i < ARRAY_SIZE(s->slots); i++)
s->slots[i].slot = i;
diff --git a/loader.c b/loader.c
index cf603cc099..71b9ba7852 100644
--- a/loader.c
+++ b/loader.c
@@ -266,8 +266,6 @@ static void *load_at(int fd, int offset, int size)
if (lseek(fd, offset, SEEK_SET) < 0)
return NULL;
ptr = qemu_malloc(size);
- if (!ptr)
- return NULL;
if (read(fd, ptr, size) != size) {
qemu_free(ptr);
return NULL;
@@ -505,8 +503,6 @@ int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
*ep = hdr->ih_ep;
data = qemu_malloc(hdr->ih_size);
- if (!data)
- goto out;
if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
fprintf(stderr, "Error reading file\n");
diff --git a/migration-exec.c b/migration-exec.c
index caeed4bbc0..6ed322a989 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -61,10 +61,6 @@ MigrationState *exec_start_outgoing_migration(const char *command,
FILE *f;
s = qemu_mallocz(sizeof(*s));
- if (s == NULL) {
- dprintf("Unable to allocate FdMigrationState\n");
- goto err;
- }
f = popen(command, "w");
if (f == NULL) {
@@ -109,7 +105,6 @@ err_after_open:
pclose(f);
err_after_alloc:
qemu_free(s);
-err:
return NULL;
}
diff --git a/migration-tcp.c b/migration-tcp.c
index 6fc1943d8b..3f5b1049c0 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -89,8 +89,6 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,
return NULL;
s = qemu_mallocz(sizeof(*s));
- if (s == NULL)
- return NULL;
s->get_error = socket_errno;
s->write = socket_write;
diff --git a/monitor.c b/monitor.c
index 8815688c18..354a792d40 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1371,10 +1371,6 @@ static void do_wav_capture (const char *path,
CaptureState *s;
s = qemu_mallocz (sizeof (*s));
- if (!s) {
- term_printf ("Not enough memory to add wave capture\n");
- return;
- }
freq = has_freq ? freq : 44100;
bits = has_bits ? bits : 16;
diff --git a/net.c b/net.c
index 8d9b3de253..e7c097e1c8 100644
--- a/net.c
+++ b/net.c
@@ -333,8 +333,6 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
{
VLANClientState *vc, **pvc;
vc = qemu_mallocz(sizeof(VLANClientState));
- if (!vc)
- return NULL;
vc->model = strdup(model);
if (name)
vc->name = strdup(name);
@@ -728,8 +726,6 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
TAPState *s;
s = qemu_mallocz(sizeof(TAPState));
- if (!s)
- return NULL;
s->fd = fd;
s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
#ifdef HAVE_IOVEC
@@ -1049,8 +1045,6 @@ static int net_vde_init(VLANState *vlan, const char *model,
};
s = qemu_mallocz(sizeof(VDEState));
- if (!s)
- return -1;
s->vde = vde_open(init_sock, "QEMU", &args);
if (!s->vde){
free(s);
@@ -1274,8 +1268,6 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
}
s = qemu_mallocz(sizeof(NetSocketState));
- if (!s)
- return NULL;
s->fd = fd;
s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive_dgram, NULL, s);
@@ -1304,8 +1296,6 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
{
NetSocketState *s;
s = qemu_mallocz(sizeof(NetSocketState));
- if (!s)
- return NULL;
s->fd = fd;
s->vc = qemu_new_vlan_client(vlan, model, name,
net_socket_receive, NULL, s);
@@ -1383,8 +1373,6 @@ static int net_socket_listen_init(VLANState *vlan,
return -1;
s = qemu_mallocz(sizeof(NetSocketListenState));
- if (!s)
- return -1;
fd = socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0) {
@@ -1504,8 +1492,6 @@ VLANState *qemu_find_vlan(int id)
return vlan;
}
vlan = qemu_mallocz(sizeof(VLANState));
- if (!vlan)
- return NULL;
vlan->id = id;
vlan->next = NULL;
pvlan = &first_vlan;
diff --git a/qemu-char.c b/qemu-char.c
index f8491878be..6e10c67b36 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -193,8 +193,6 @@ static CharDriverState *qemu_chr_open_null(void)
CharDriverState *chr;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- return NULL;
chr->chr_write = null_chr_write;
return chr;
}
@@ -425,13 +423,7 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
MuxDriver *d;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- return NULL;
d = qemu_mallocz(sizeof(MuxDriver));
- if (!d) {
- free(chr);
- return NULL;
- }
chr->opaque = d;
d->drv = drv;
@@ -576,13 +568,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
FDCharDriver *s;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- return NULL;
s = qemu_mallocz(sizeof(FDCharDriver));
- if (!s) {
- free(chr);
- return NULL;
- }
s->fd_in = fd_in;
s->fd_out = fd_out;
chr->opaque = s;
@@ -929,13 +915,7 @@ static CharDriverState *qemu_chr_open_pty(void)
#endif
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- return NULL;
s = qemu_mallocz(sizeof(PtyCharDriver));
- if (!s) {
- qemu_free(chr);
- return NULL;
- }
if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) {
return NULL;
@@ -1246,19 +1226,10 @@ static CharDriverState *qemu_chr_open_pp(const char *filename)
}
drv = qemu_mallocz(sizeof(ParallelCharDriver));
- if (!drv) {
- close(fd);
- return NULL;
- }
drv->fd = fd;
drv->mode = IEEE1284_MODE_COMPAT;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr) {
- qemu_free(drv);
- close(fd);
- return NULL;
- }
chr->chr_write = null_chr_write;
chr->chr_ioctl = pp_ioctl;
chr->chr_close = pp_close;
@@ -1318,10 +1289,6 @@ static CharDriverState *qemu_chr_open_pp(const char *filename)
return NULL;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr) {
- close(fd);
- return NULL;
- }
chr->opaque = (void *)fd;
chr->chr_write = null_chr_write;
chr->chr_ioctl = pp_ioctl;
@@ -1535,13 +1502,7 @@ static CharDriverState *qemu_chr_open_win(const char *filename)
WinCharState *s;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- return NULL;
s = qemu_mallocz(sizeof(WinCharState));
- if (!s) {
- free(chr);
- return NULL;
- }
chr->opaque = s;
chr->chr_write = win_chr_write;
chr->chr_close = win_chr_close;
@@ -1640,13 +1601,7 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename)
WinCharState *s;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- return NULL;
s = qemu_mallocz(sizeof(WinCharState));
- if (!s) {
- free(chr);
- return NULL;
- }
chr->opaque = s;
chr->chr_write = win_chr_write;
chr->chr_close = win_chr_close;
@@ -1666,13 +1621,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out)
WinCharState *s;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- return NULL;
s = qemu_mallocz(sizeof(WinCharState));
- if (!s) {
- free(chr);
- return NULL;
- }
s->hcom = fd_out;
chr->opaque = s;
chr->chr_write = win_chr_write;
@@ -1774,11 +1723,7 @@ static CharDriverState *qemu_chr_open_udp(const char *def)
struct sockaddr_in saddr;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- goto return_err;
s = qemu_mallocz(sizeof(NetCharDriver));
- if (!s)
- goto return_err;
fd = socket(PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
@@ -2044,11 +1989,7 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
is_waitconnect = 0;
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- goto fail;
s = qemu_mallocz(sizeof(TCPCharDriver));
- if (!s)
- goto fail;
if (is_listen) {
chr->filename = qemu_malloc(256);
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 59bd2f14f3..0af97ca2c7 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -409,8 +409,6 @@ int main(int argc, char **argv)
}
sharing_fds = qemu_malloc((shared + 1) * sizeof(int));
- if (sharing_fds == NULL)
- errx(ENOMEM, "Cannot allocate sharing fds");
if (socket) {
sharing_fds[0] = unix_socket_incoming(socket);
diff --git a/qemu-tool.c b/qemu-tool.c
index c0b1cad669..4dda5af58b 100644
--- a/qemu-tool.c
+++ b/qemu-tool.c
@@ -43,10 +43,8 @@ QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
QEMUBH *bh;
bh = qemu_malloc(sizeof(*bh));
- if (bh) {
- bh->cb = cb;
- bh->opaque = opaque;
- }
+ bh->cb = cb;
+ bh->opaque = opaque;
return bh;
}
diff --git a/readline.c b/readline.c
index 7bf9a5e1d4..85728412e6 100644
--- a/readline.c
+++ b/readline.c
@@ -307,8 +307,6 @@ static void term_completion(void)
nb_completions = 0;
cmdline = qemu_malloc(term_cmd_buf_index + 1);
- if (!cmdline)
- return;
memcpy(cmdline, term_cmd_buf, term_cmd_buf_index);
cmdline[term_cmd_buf_index] = '\0';
readline_find_completion(cmdline);
diff --git a/savevm.c b/savevm.c
index 729e84977f..3eb2000ab2 100644
--- a/savevm.c
+++ b/savevm.c
@@ -214,10 +214,6 @@ QEMUFile *qemu_popen(FILE *popen_file, const char *mode)
}
s = qemu_mallocz(sizeof(QEMUFilePopen));
- if (!s) {
- fprintf(stderr, "qemu_popen: malloc failed\n");
- return NULL;
- }
s->popen_file = popen_file;
@@ -246,9 +242,6 @@ QEMUFile *qemu_fopen_socket(int fd)
{
QEMUFileSocket *s = qemu_mallocz(sizeof(QEMUFileSocket));
- if (s == NULL)
- return NULL;
-
s->fd = fd;
s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, NULL);
return s->file;
@@ -288,8 +281,6 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)
QEMUFileStdio *s;
s = qemu_mallocz(sizeof(QEMUFileStdio));
- if (!s)
- return NULL;
s->outfile = fopen(filename, mode);
if (!s->outfile)
@@ -339,8 +330,6 @@ static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int64_t offset, int is_wr
QEMUFileBdrv *s;
s = qemu_mallocz(sizeof(QEMUFileBdrv));
- if (!s)
- return NULL;
s->bs = bs;
s->base_offset = offset;
@@ -359,8 +348,6 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
QEMUFile *f;
f = qemu_mallocz(sizeof(QEMUFile));
- if (!f)
- return NULL;
f->opaque = opaque;
f->put_buffer = put_buffer;
@@ -615,8 +602,6 @@ int register_savevm_live(const char *idstr,
static int global_section_id;
se = qemu_malloc(sizeof(SaveStateEntry));
- if (!se)
- return -1;
pstrcpy(se->idstr, sizeof(se->idstr), idstr);
se->instance_id = (instance_id == -1) ? 0 : instance_id;
se->version_id = version_id;
@@ -908,10 +893,6 @@ int qemu_loadvm_state(QEMUFile *f)
/* Add entry */
le = qemu_mallocz(sizeof(*le));
- if (le == NULL) {
- ret = -ENOMEM;
- goto out;
- }
le->se = se;
le->section_id = section_id;
diff --git a/sdl.c b/sdl.c
index cfdf852373..266fbcc8c5 100644
--- a/sdl.c
+++ b/sdl.c
@@ -638,8 +638,6 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
}
dcl = qemu_mallocz(sizeof(DisplayChangeListener));
- if (!dcl)
- exit(1);
dcl->dpy_update = sdl_update;
dcl->dpy_resize = sdl_resize;
dcl->dpy_refresh = sdl_refresh;
diff --git a/usb-bsd.c b/usb-bsd.c
index a8a805f064..fa4093cc12 100644
--- a/usb-bsd.c
+++ b/usb-bsd.c
@@ -340,8 +340,6 @@ USBDevice *usb_host_device_open(const char *devname)
if (dfd >= 0) {
dev = qemu_mallocz(sizeof(USBHostDevice));
- if (!dev)
- goto fail;
dev->devfd = dfd;
if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {
diff --git a/usb-linux.c b/usb-linux.c
index fb1153bbd4..f19f0c4107 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -441,10 +441,6 @@ static int usb_host_handle_data(USBHostDevice *s, USBPacket *p)
int ret;
aurb = async_alloc();
- if (!aurb) {
- dprintf("husb: async malloc failed\n");
- return USB_RET_NAK;
- }
aurb->hdev = s;
aurb->packet = p;
@@ -585,10 +581,6 @@ static int usb_host_handle_control(USBHostDevice *s, USBPacket *p)
/* The rest are asynchronous */
aurb = async_alloc();
- if (!aurb) {
- dprintf("husb: async malloc failed\n");
- return USB_RET_NAK;
- }
aurb->hdev = s;
aurb->packet = p;
@@ -898,8 +890,6 @@ static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *p
char buf[1024];
dev = qemu_mallocz(sizeof(USBHostDevice));
- if (!dev)
- goto fail;
dev->bus_num = bus_num;
dev->addr = addr;
@@ -1308,14 +1298,8 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
/* the module setting (used later for opening devices) */
usb_host_device_path = qemu_mallocz(strlen(devpath)+1);
- if (usb_host_device_path) {
- strcpy(usb_host_device_path, devpath);
- term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path);
- } else {
- /* out of memory? */
- perror("husb: unable to allocate memory for device path");
- return -ENOMEM;
- }
+ strcpy(usb_host_device_path, devpath);
+ term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path);
}
switch (usb_fs_type) {
@@ -1455,10 +1439,6 @@ static int usb_host_auto_add(const char *spec)
return -1;
f = qemu_mallocz(sizeof(*f));
- if (!f) {
- fprintf(stderr, "husb: failed to allocate auto filter\n");
- return -1;
- }
*f = filter;
diff --git a/vl.c b/vl.c
index 36765378a4..aff2b2ce3d 100644
--- a/vl.c
+++ b/vl.c
@@ -546,8 +546,6 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
QEMUPutMouseEntry *s, *cursor;
s = qemu_mallocz(sizeof(QEMUPutMouseEntry));
- if (!s)
- return NULL;
s->qemu_put_mouse_event = func;
s->qemu_put_mouse_event_opaque = opaque;
@@ -1098,8 +1096,6 @@ static QEMUClock *qemu_new_clock(int type)
{
QEMUClock *clock;
clock = qemu_mallocz(sizeof(QEMUClock));
- if (!clock)
- return NULL;
clock->type = type;
return clock;
}
@@ -2808,10 +2804,6 @@ DisplayState *get_displaystate(void)
static void dumb_display_init(void)
{
DisplayState *ds = qemu_mallocz(sizeof(DisplayState));
- if (ds == NULL) {
- fprintf(stderr, "dumb_display_init: DisplayState allocation failed\n");
- exit(1);
- }
ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
register_displaystate(ds);
}
@@ -2863,8 +2855,6 @@ int qemu_set_fd_handler2(int fd,
goto found;
}
ioh = qemu_mallocz(sizeof(IOHandlerRecord));
- if (!ioh)
- return -1;
ioh->next = first_io_handler;
first_io_handler = ioh;
found:
@@ -2902,8 +2892,6 @@ int qemu_add_polling_cb(PollingFunc *func, void *opaque)
{
PollingEntry **ppe, *pe;
pe = qemu_mallocz(sizeof(PollingEntry));
- if (!pe)
- return -1;
pe->func = func;
pe->opaque = opaque;
for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next);
@@ -3273,8 +3261,6 @@ QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
{
QEMUBH *bh;
bh = qemu_mallocz(sizeof(QEMUBH));
- if (!bh)
- return NULL;
bh->cb = cb;
bh->opaque = opaque;
bh->next = first_bh;
@@ -3432,8 +3418,6 @@ VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
VMChangeStateEntry *e;
e = qemu_mallocz(sizeof (*e));
- if (!e)
- return NULL;
e->cb = cb;
e->opaque = opaque;
diff --git a/vnc.c b/vnc.c
index 0c4d96e250..68df599615 100644
--- a/vnc.c
+++ b/vnc.c
@@ -471,8 +471,8 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
int has_fg, has_bg;
uint8_t *last_fg, *last_bg;
- last_fg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
- last_bg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
+ last_fg = (uint8_t *) qemu_malloc(vs->serverds.pf.bytes_per_pixel);
+ last_bg = (uint8_t *) qemu_malloc(vs->serverds.pf.bytes_per_pixel);
has_fg = has_bg = 0;
for (j = y; j < (y + h); j += 16) {
for (i = x; i < (x + w); i += 16) {
@@ -2237,8 +2237,6 @@ void vnc_display_init(DisplayState *ds)
vs = qemu_mallocz(sizeof(VncState));
dcl = qemu_mallocz(sizeof(DisplayChangeListener));
- if (!vs || !dcl)
- exit(1);
ds->opaque = vs;
dcl->idle = 1;
@@ -2289,8 +2287,7 @@ static int vnc_set_x509_credential(VncState *vs,
*cred = NULL;
}
- if (!(*cred = qemu_malloc(strlen(certdir) + strlen(filename) + 2)))
- return -1;
+ *cred = qemu_malloc(strlen(certdir) + strlen(filename) + 2);
strcpy(*cred, certdir);
strcat(*cred, "/");