qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [6531] toplevel: remove error handling from qemu_malloc() c


From: Anthony Liguori
Subject: [Qemu-devel] [6531] toplevel: remove error handling from qemu_malloc() callers ( Avi Kivity)
Date: Thu, 05 Feb 2009 22:06:19 +0000

Revision: 6531
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6531
Author:   aliguori
Date:     2009-02-05 22:06:18 +0000 (Thu, 05 Feb 2009)

Log Message:
-----------
toplevel: remove error handling from qemu_malloc() callers (Avi Kivity)

Signed-off-by: Avi Kivity <address@hidden>
Signed-off-by: Anthony Liguori <address@hidden>

Modified Paths:
--------------
    trunk/aio.c
    trunk/buffered_file.c
    trunk/console.c
    trunk/cris-dis.c
    trunk/curses.c
    trunk/device_tree.c
    trunk/exec.c
    trunk/gdbstub.c
    trunk/keymaps.c
    trunk/kvm-all.c
    trunk/loader.c
    trunk/migration-exec.c
    trunk/migration-tcp.c
    trunk/monitor.c
    trunk/net.c
    trunk/qemu-char.c
    trunk/qemu-nbd.c
    trunk/qemu-tool.c
    trunk/readline.c
    trunk/savevm.c
    trunk/sdl.c
    trunk/usb-bsd.c
    trunk/usb-linux.c
    trunk/vl.c
    trunk/vnc.c

Modified: trunk/aio.c
===================================================================
--- trunk/aio.c 2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/aio.c 2009-02-05 22:06:18 UTC (rev 6531)
@@ -79,8 +79,6 @@
         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);
         }

Modified: trunk/buffered_file.c
===================================================================
--- trunk/buffered_file.c       2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/buffered_file.c       2009-02-05 22:06:18 UTC (rev 6531)
@@ -228,8 +228,6 @@
     QEMUFileBuffered *s;
 
     s = qemu_mallocz(sizeof(*s));
-    if (s == NULL)
-        return NULL;
 
     s->opaque = opaque;
     s->xfer_limit = bytes_per_sec / 10;

Modified: trunk/console.c
===================================================================
--- trunk/console.c     2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/console.c     2009-02-05 22:06:18 UTC (rev 6531)
@@ -1246,9 +1246,6 @@
     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 *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 *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 @@
 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 @@
     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 @@
         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 @@
                                               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;

Modified: trunk/cris-dis.c
===================================================================
--- trunk/cris-dis.c    2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/cris-dis.c    2009-02-05 22:06:18 UTC (rev 6531)
@@ -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 @@
   /* 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]));
     }

Modified: trunk/curses.c
===================================================================
--- trunk/curses.c      2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/curses.c      2009-02-05 22:06:18 UTC (rev 6531)
@@ -361,8 +361,6 @@
 #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;

Modified: trunk/device_tree.c
===================================================================
--- trunk/device_tree.c 2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/device_tree.c 2009-02-05 22:06:18 UTC (rev 6531)
@@ -43,10 +43,6 @@
 
     /* 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);
 

Modified: trunk/exec.c
===================================================================
--- trunk/exec.c        2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/exec.c        2009-02-05 22:06:18 UTC (rev 6531)
@@ -476,10 +476,6 @@
     }
 #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 @@
     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 @@
         return -EINVAL;
     }
     wp = qemu_malloc(sizeof(*wp));
-    if (!wp)
-        return -ENOMEM;
 
     wp->vaddr = addr;
     wp->len_mask = len_mask;
@@ -1384,8 +1376,6 @@
     CPUBreakpoint *bp;
 
     bp = qemu_malloc(sizeof(*bp));
-    if (!bp)
-        return -ENOMEM;
 
     bp->pc = pc;
     bp->flags = flags;
@@ -2795,17 +2785,16 @@
     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;
 }

Modified: trunk/gdbstub.c
===================================================================
--- trunk/gdbstub.c     2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/gdbstub.c     2009-02-05 22:06:18 UTC (rev 6531)
@@ -2189,11 +2189,6 @@
     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 @@
         return -1;
 
     s = qemu_mallocz(sizeof(GDBState));
-    if (!s) {
-        return -1;
-    }
     s->c_cpu = first_cpu;
     s->g_cpu = first_cpu;
     s->chr = chr;

Modified: trunk/keymaps.c
===================================================================
--- trunk/keymaps.c     2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/keymaps.c     2009-02-05 22:06:18 UTC (rev 6531)
@@ -67,11 +67,9 @@
     }
     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 @@
 
     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);

Modified: trunk/kvm-all.c
===================================================================
--- trunk/kvm-all.c     2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/kvm-all.c     2009-02-05 22:06:18 UTC (rev 6531)
@@ -220,11 +220,6 @@
     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 @@
         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;

Modified: trunk/loader.c
===================================================================
--- trunk/loader.c      2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/loader.c      2009-02-05 22:06:18 UTC (rev 6531)
@@ -266,8 +266,6 @@
     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 @@
 
     *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");

Modified: trunk/migration-exec.c
===================================================================
--- trunk/migration-exec.c      2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/migration-exec.c      2009-02-05 22:06:18 UTC (rev 6531)
@@ -61,10 +61,6 @@
     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 @@
     pclose(f);
 err_after_alloc:
     qemu_free(s);
-err:
     return NULL;
 }
 

Modified: trunk/migration-tcp.c
===================================================================
--- trunk/migration-tcp.c       2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/migration-tcp.c       2009-02-05 22:06:18 UTC (rev 6531)
@@ -89,8 +89,6 @@
         return NULL;
 
     s = qemu_mallocz(sizeof(*s));
-    if (s == NULL)
-        return NULL;
 
     s->get_error = socket_errno;
     s->write = socket_write;

Modified: trunk/monitor.c
===================================================================
--- trunk/monitor.c     2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/monitor.c     2009-02-05 22:06:18 UTC (rev 6531)
@@ -1371,10 +1371,6 @@
     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;

Modified: trunk/net.c
===================================================================
--- trunk/net.c 2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/net.c 2009-02-05 22:06:18 UTC (rev 6531)
@@ -333,8 +333,6 @@
 {
     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 @@
     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 @@
     };
 
     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 @@
     }
 
     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 @@
 {
     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 @@
         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 @@
             return vlan;
     }
     vlan = qemu_mallocz(sizeof(VLANState));
-    if (!vlan)
-        return NULL;
     vlan->id = id;
     vlan->next = NULL;
     pvlan = &first_vlan;

Modified: trunk/qemu-char.c
===================================================================
--- trunk/qemu-char.c   2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/qemu-char.c   2009-02-05 22:06:18 UTC (rev 6531)
@@ -193,8 +193,6 @@
     CharDriverState *chr;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        return NULL;
     chr->chr_write = null_chr_write;
     return chr;
 }
@@ -425,13 +423,7 @@
     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 @@
     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 @@
 #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 @@
     }
 
     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 @@
         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 @@
     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 @@
     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 @@
     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 @@
     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 @@
         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);

Modified: trunk/qemu-nbd.c
===================================================================
--- trunk/qemu-nbd.c    2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/qemu-nbd.c    2009-02-05 22:06:18 UTC (rev 6531)
@@ -409,8 +409,6 @@
     }
 
     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);

Modified: trunk/qemu-tool.c
===================================================================
--- trunk/qemu-tool.c   2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/qemu-tool.c   2009-02-05 22:06:18 UTC (rev 6531)
@@ -43,10 +43,8 @@
     QEMUBH *bh;
 
     bh = qemu_malloc(sizeof(*bh));
-    if (bh) {
-        bh->cb = cb;
-        bh->opaque = opaque;
-    }
+    bh->cb = cb;
+    bh->opaque = opaque;
 
     return bh;
 }

Modified: trunk/readline.c
===================================================================
--- trunk/readline.c    2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/readline.c    2009-02-05 22:06:18 UTC (rev 6531)
@@ -307,8 +307,6 @@
     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);

Modified: trunk/savevm.c
===================================================================
--- trunk/savevm.c      2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/savevm.c      2009-02-05 22:06:18 UTC (rev 6531)
@@ -214,10 +214,6 @@
     }
 
     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 @@
 {
     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 @@
     QEMUFileStdio *s;
 
     s = qemu_mallocz(sizeof(QEMUFileStdio));
-    if (!s)
-        return NULL;
 
     s->outfile = fopen(filename, mode);
     if (!s->outfile)
@@ -339,8 +330,6 @@
     QEMUFileBdrv *s;
 
     s = qemu_mallocz(sizeof(QEMUFileBdrv));
-    if (!s)
-        return NULL;
 
     s->bs = bs;
     s->base_offset = offset;
@@ -359,8 +348,6 @@
     QEMUFile *f;
 
     f = qemu_mallocz(sizeof(QEMUFile));
-    if (!f)
-        return NULL;
 
     f->opaque = opaque;
     f->put_buffer = put_buffer;
@@ -615,8 +602,6 @@
     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 @@
 
             /* Add entry */
             le = qemu_mallocz(sizeof(*le));
-            if (le == NULL) {
-                ret = -ENOMEM;
-                goto out;
-            }
 
             le->se = se;
             le->section_id = section_id;

Modified: trunk/sdl.c
===================================================================
--- trunk/sdl.c 2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/sdl.c 2009-02-05 22:06:18 UTC (rev 6531)
@@ -638,8 +638,6 @@
     }
 
     dcl = qemu_mallocz(sizeof(DisplayChangeListener));
-    if (!dcl)
-        exit(1);
     dcl->dpy_update = sdl_update;
     dcl->dpy_resize = sdl_resize;
     dcl->dpy_refresh = sdl_refresh;

Modified: trunk/usb-bsd.c
===================================================================
--- trunk/usb-bsd.c     2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/usb-bsd.c     2009-02-05 22:06:18 UTC (rev 6531)
@@ -340,8 +340,6 @@
 
     if (dfd >= 0) {
         dev = qemu_mallocz(sizeof(USBHostDevice));
-        if (!dev)
-            goto fail;
         dev->devfd = dfd;
 
         if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {

Modified: trunk/usb-linux.c
===================================================================
--- trunk/usb-linux.c   2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/usb-linux.c   2009-02-05 22:06:18 UTC (rev 6531)
@@ -441,10 +441,6 @@
     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 @@
     /* 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 @@
     char buf[1024];
 
     dev = qemu_mallocz(sizeof(USBHostDevice));
-    if (!dev)
-        goto fail;
 
     dev->bus_num = bus_num;
     dev->addr = addr;
@@ -1308,14 +1298,8 @@
 
         /* 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 @@
         return -1;
 
     f = qemu_mallocz(sizeof(*f));
-    if (!f) {
-        fprintf(stderr, "husb: failed to allocate auto filter\n");
-        return -1;
-    }
 
     *f = filter; 
 

Modified: trunk/vl.c
===================================================================
--- trunk/vl.c  2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/vl.c  2009-02-05 22:06:18 UTC (rev 6531)
@@ -546,8 +546,6 @@
     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 @@
 {
     QEMUClock *clock;
     clock = qemu_mallocz(sizeof(QEMUClock));
-    if (!clock)
-        return NULL;
     clock->type = type;
     return clock;
 }
@@ -2808,10 +2804,6 @@
 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 @@
                 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 @@
 {
     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 *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 *e;
 
     e = qemu_mallocz(sizeof (*e));
-    if (!e)
-        return NULL;
 
     e->cb = cb;
     e->opaque = opaque;

Modified: trunk/vnc.c
===================================================================
--- trunk/vnc.c 2009-02-05 22:06:11 UTC (rev 6530)
+++ trunk/vnc.c 2009-02-05 22:06:18 UTC (rev 6531)
@@ -471,8 +471,8 @@
     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 @@
 
     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 @@
        *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, "/");






reply via email to

[Prev in Thread] Current Thread [Next in Thread]