Commit 3ec88e80365c889f824d9a171fbf197b46a7c03f
1 parent
8a1d02ab
block: 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@6527 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
10 changed files
with
14 additions
and
103 deletions
block-bochs.c
| ... | ... | @@ -149,8 +149,6 @@ static int bochs_open(BlockDriverState *bs, const char *filename, int flags) |
| 149 | 149 | |
| 150 | 150 | s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog); |
| 151 | 151 | s->catalog_bitmap = qemu_malloc(s->catalog_size * 4); |
| 152 | - if (!s->catalog_bitmap) | |
| 153 | - goto fail; | |
| 154 | 152 | if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) != |
| 155 | 153 | s->catalog_size * 4) |
| 156 | 154 | goto fail; | ... | ... |
block-cloop.c
| ... | ... | @@ -75,8 +75,7 @@ cloop_close: |
| 75 | 75 | |
| 76 | 76 | /* read offsets */ |
| 77 | 77 | offsets_size=s->n_blocks*sizeof(uint64_t); |
| 78 | - if(!(s->offsets=(uint64_t*)malloc(offsets_size))) | |
| 79 | - goto cloop_close; | |
| 78 | + s->offsets=(uint64_t*)qemu_malloc(offsets_size); | |
| 80 | 79 | if(read(s->fd,s->offsets,offsets_size)<offsets_size) |
| 81 | 80 | goto cloop_close; |
| 82 | 81 | for(i=0;i<s->n_blocks;i++) { |
| ... | ... | @@ -89,10 +88,8 @@ cloop_close: |
| 89 | 88 | } |
| 90 | 89 | |
| 91 | 90 | /* initialize zlib engine */ |
| 92 | - if(!(s->compressed_block = malloc(max_compressed_block_size+1))) | |
| 93 | - goto cloop_close; | |
| 94 | - if(!(s->uncompressed_block = malloc(s->block_size))) | |
| 95 | - goto cloop_close; | |
| 91 | + s->compressed_block = qemu_malloc(max_compressed_block_size+1); | |
| 92 | + s->uncompressed_block = qemu_malloc(s->block_size); | |
| 96 | 93 | if(inflateInit(&s->zstream) != Z_OK) |
| 97 | 94 | goto cloop_close; |
| 98 | 95 | s->current_block=s->n_blocks; | ... | ... |
block-dmg.c
| ... | ... | @@ -159,10 +159,8 @@ dmg_close: |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /* initialize zlib engine */ |
| 162 | - if(!(s->compressed_chunk = malloc(max_compressed_size+1))) | |
| 163 | - goto dmg_close; | |
| 164 | - if(!(s->uncompressed_chunk = malloc(512*max_sectors_per_chunk))) | |
| 165 | - goto dmg_close; | |
| 162 | + s->compressed_chunk = qemu_malloc(max_compressed_size+1); | |
| 163 | + s->uncompressed_chunk = qemu_malloc(512*max_sectors_per_chunk); | |
| 166 | 164 | if(inflateInit(&s->zstream) != Z_OK) |
| 167 | 165 | goto dmg_close; |
| 168 | 166 | ... | ... |
block-parallels.c
| ... | ... | @@ -101,8 +101,6 @@ static int parallels_open(BlockDriverState *bs, const char *filename, int flags) |
| 101 | 101 | |
| 102 | 102 | s->catalog_size = le32_to_cpu(ph.catalog_entries); |
| 103 | 103 | s->catalog_bitmap = qemu_malloc(s->catalog_size * 4); |
| 104 | - if (!s->catalog_bitmap) | |
| 105 | - goto fail; | |
| 106 | 104 | if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) != |
| 107 | 105 | s->catalog_size * 4) |
| 108 | 106 | goto fail; | ... | ... |
block-qcow2.c
| ... | ... | @@ -259,8 +259,6 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) |
| 259 | 259 | goto fail; |
| 260 | 260 | s->l1_table_offset = header.l1_table_offset; |
| 261 | 261 | s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); |
| 262 | - if (!s->l1_table) | |
| 263 | - goto fail; | |
| 264 | 262 | if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) != |
| 265 | 263 | s->l1_size * sizeof(uint64_t)) |
| 266 | 264 | goto fail; |
| ... | ... | @@ -269,16 +267,10 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) |
| 269 | 267 | } |
| 270 | 268 | /* alloc L2 cache */ |
| 271 | 269 | s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t)); |
| 272 | - if (!s->l2_cache) | |
| 273 | - goto fail; | |
| 274 | 270 | s->cluster_cache = qemu_malloc(s->cluster_size); |
| 275 | - if (!s->cluster_cache) | |
| 276 | - goto fail; | |
| 277 | 271 | /* one more sector for decompressed data alignment */ |
| 278 | 272 | s->cluster_data = qemu_malloc(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size |
| 279 | 273 | + 512); |
| 280 | - if (!s->cluster_data) | |
| 281 | - goto fail; | |
| 282 | 274 | s->cluster_cache_offset = -1; |
| 283 | 275 | |
| 284 | 276 | if (refcount_init(bs) < 0) |
| ... | ... | @@ -459,8 +451,6 @@ static int grow_l1_table(BlockDriverState *bs, int min_size) |
| 459 | 451 | |
| 460 | 452 | new_l1_size2 = sizeof(uint64_t) * new_l1_size; |
| 461 | 453 | new_l1_table = qemu_mallocz(new_l1_size2); |
| 462 | - if (!new_l1_table) | |
| 463 | - return -ENOMEM; | |
| 464 | 454 | memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t)); |
| 465 | 455 | |
| 466 | 456 | /* write new table (align to cluster) */ |
| ... | ... | @@ -893,8 +883,7 @@ static int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset, |
| 893 | 883 | if (m->nb_clusters == 0) |
| 894 | 884 | return 0; |
| 895 | 885 | |
| 896 | - if (!(old_cluster = qemu_malloc(m->nb_clusters * sizeof(uint64_t)))) | |
| 897 | - return -ENOMEM; | |
| 886 | + old_cluster = qemu_malloc(m->nb_clusters * sizeof(uint64_t)); | |
| 898 | 887 | |
| 899 | 888 | /* copy content of unmodified sectors */ |
| 900 | 889 | start_sect = (m->offset & ~(s->cluster_size - 1)) >> 9; |
| ... | ... | @@ -1393,10 +1382,6 @@ static void qcow_aio_write_cb(void *opaque, int ret) |
| 1393 | 1382 | if (!acb->cluster_data) { |
| 1394 | 1383 | acb->cluster_data = qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS * |
| 1395 | 1384 | s->cluster_size); |
| 1396 | - if (!acb->cluster_data) { | |
| 1397 | - ret = -ENOMEM; | |
| 1398 | - goto fail; | |
| 1399 | - } | |
| 1400 | 1385 | } |
| 1401 | 1386 | encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf, |
| 1402 | 1387 | acb->n, 1, &s->aes_encrypt_key); |
| ... | ... | @@ -1521,11 +1506,7 @@ static int qcow_create(const char *filename, int64_t total_size, |
| 1521 | 1506 | offset += align_offset(l1_size * sizeof(uint64_t), s->cluster_size); |
| 1522 | 1507 | |
| 1523 | 1508 | s->refcount_table = qemu_mallocz(s->cluster_size); |
| 1524 | - if (!s->refcount_table) | |
| 1525 | - goto fail; | |
| 1526 | 1509 | s->refcount_block = qemu_mallocz(s->cluster_size); |
| 1527 | - if (!s->refcount_block) | |
| 1528 | - goto fail; | |
| 1529 | 1510 | |
| 1530 | 1511 | s->refcount_table_offset = offset; |
| 1531 | 1512 | header.refcount_table_offset = cpu_to_be64(offset); |
| ... | ... | @@ -1562,11 +1543,6 @@ static int qcow_create(const char *filename, int64_t total_size, |
| 1562 | 1543 | qemu_free(s->refcount_block); |
| 1563 | 1544 | close(fd); |
| 1564 | 1545 | return 0; |
| 1565 | - fail: | |
| 1566 | - qemu_free(s->refcount_table); | |
| 1567 | - qemu_free(s->refcount_block); | |
| 1568 | - close(fd); | |
| 1569 | - return -ENOMEM; | |
| 1570 | 1546 | } |
| 1571 | 1547 | |
| 1572 | 1548 | static int qcow_make_empty(BlockDriverState *bs) |
| ... | ... | @@ -1613,8 +1589,6 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, |
| 1613 | 1589 | return -EINVAL; |
| 1614 | 1590 | |
| 1615 | 1591 | out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128); |
| 1616 | - if (!out_buf) | |
| 1617 | - return -ENOMEM; | |
| 1618 | 1592 | |
| 1619 | 1593 | /* best compression, small window, no zlib header */ |
| 1620 | 1594 | memset(&strm, 0, sizeof(strm)); |
| ... | ... | @@ -1699,8 +1673,6 @@ static int update_snapshot_refcount(BlockDriverState *bs, |
| 1699 | 1673 | l1_allocated = 0; |
| 1700 | 1674 | if (l1_table_offset != s->l1_table_offset) { |
| 1701 | 1675 | l1_table = qemu_malloc(l1_size2); |
| 1702 | - if (!l1_table) | |
| 1703 | - goto fail; | |
| 1704 | 1676 | l1_allocated = 1; |
| 1705 | 1677 | if (bdrv_pread(s->hd, l1_table_offset, |
| 1706 | 1678 | l1_table, l1_size2) != l1_size2) |
| ... | ... | @@ -1715,8 +1687,6 @@ static int update_snapshot_refcount(BlockDriverState *bs, |
| 1715 | 1687 | |
| 1716 | 1688 | l2_size = s->l2_size * sizeof(uint64_t); |
| 1717 | 1689 | l2_table = qemu_malloc(l2_size); |
| 1718 | - if (!l2_table) | |
| 1719 | - goto fail; | |
| 1720 | 1690 | l1_modified = 0; |
| 1721 | 1691 | for(i = 0; i < l1_size; i++) { |
| 1722 | 1692 | l2_offset = l1_table[i]; |
| ... | ... | @@ -1827,8 +1797,6 @@ static int qcow_read_snapshots(BlockDriverState *bs) |
| 1827 | 1797 | |
| 1828 | 1798 | offset = s->snapshots_offset; |
| 1829 | 1799 | s->snapshots = qemu_mallocz(s->nb_snapshots * sizeof(QCowSnapshot)); |
| 1830 | - if (!s->snapshots) | |
| 1831 | - goto fail; | |
| 1832 | 1800 | for(i = 0; i < s->nb_snapshots; i++) { |
| 1833 | 1801 | offset = align_offset(offset, 8); |
| 1834 | 1802 | if (bdrv_pread(s->hd, offset, &h, sizeof(h)) != sizeof(h)) |
| ... | ... | @@ -1849,16 +1817,12 @@ static int qcow_read_snapshots(BlockDriverState *bs) |
| 1849 | 1817 | offset += extra_data_size; |
| 1850 | 1818 | |
| 1851 | 1819 | sn->id_str = qemu_malloc(id_str_size + 1); |
| 1852 | - if (!sn->id_str) | |
| 1853 | - goto fail; | |
| 1854 | 1820 | if (bdrv_pread(s->hd, offset, sn->id_str, id_str_size) != id_str_size) |
| 1855 | 1821 | goto fail; |
| 1856 | 1822 | offset += id_str_size; |
| 1857 | 1823 | sn->id_str[id_str_size] = '\0'; |
| 1858 | 1824 | |
| 1859 | 1825 | sn->name = qemu_malloc(name_size + 1); |
| 1860 | - if (!sn->name) | |
| 1861 | - goto fail; | |
| 1862 | 1826 | if (bdrv_pread(s->hd, offset, sn->name, name_size) != name_size) |
| 1863 | 1827 | goto fail; |
| 1864 | 1828 | offset += name_size; |
| ... | ... | @@ -2024,8 +1988,6 @@ static int qcow_snapshot_create(BlockDriverState *bs, |
| 2024 | 1988 | sn->l1_size = s->l1_size; |
| 2025 | 1989 | |
| 2026 | 1990 | l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); |
| 2027 | - if (!l1_table) | |
| 2028 | - goto fail; | |
| 2029 | 1991 | for(i = 0; i < s->l1_size; i++) { |
| 2030 | 1992 | l1_table[i] = cpu_to_be64(s->l1_table[i]); |
| 2031 | 1993 | } |
| ... | ... | @@ -2037,8 +1999,6 @@ static int qcow_snapshot_create(BlockDriverState *bs, |
| 2037 | 1999 | l1_table = NULL; |
| 2038 | 2000 | |
| 2039 | 2001 | snapshots1 = qemu_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot)); |
| 2040 | - if (!snapshots1) | |
| 2041 | - goto fail; | |
| 2042 | 2002 | if (s->snapshots) { |
| 2043 | 2003 | memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot)); |
| 2044 | 2004 | qemu_free(s->snapshots); |
| ... | ... | @@ -2145,8 +2105,6 @@ static int qcow_snapshot_list(BlockDriverState *bs, |
| 2145 | 2105 | int i; |
| 2146 | 2106 | |
| 2147 | 2107 | sn_tab = qemu_mallocz(s->nb_snapshots * sizeof(QEMUSnapshotInfo)); |
| 2148 | - if (!sn_tab) | |
| 2149 | - goto fail; | |
| 2150 | 2108 | for(i = 0; i < s->nb_snapshots; i++) { |
| 2151 | 2109 | sn_info = sn_tab + i; |
| 2152 | 2110 | sn = s->snapshots + i; |
| ... | ... | @@ -2161,10 +2119,6 @@ static int qcow_snapshot_list(BlockDriverState *bs, |
| 2161 | 2119 | } |
| 2162 | 2120 | *psn_tab = sn_tab; |
| 2163 | 2121 | return s->nb_snapshots; |
| 2164 | - fail: | |
| 2165 | - qemu_free(sn_tab); | |
| 2166 | - *psn_tab = NULL; | |
| 2167 | - return -ENOMEM; | |
| 2168 | 2122 | } |
| 2169 | 2123 | |
| 2170 | 2124 | /*********************************************************/ |
| ... | ... | @@ -2176,12 +2130,8 @@ static int refcount_init(BlockDriverState *bs) |
| 2176 | 2130 | int ret, refcount_table_size2, i; |
| 2177 | 2131 | |
| 2178 | 2132 | s->refcount_block_cache = qemu_malloc(s->cluster_size); |
| 2179 | - if (!s->refcount_block_cache) | |
| 2180 | - goto fail; | |
| 2181 | 2133 | refcount_table_size2 = s->refcount_table_size * sizeof(uint64_t); |
| 2182 | 2134 | s->refcount_table = qemu_malloc(refcount_table_size2); |
| 2183 | - if (!s->refcount_table) | |
| 2184 | - goto fail; | |
| 2185 | 2135 | if (s->refcount_table_size > 0) { |
| 2186 | 2136 | ret = bdrv_pread(s->hd, s->refcount_table_offset, |
| 2187 | 2137 | s->refcount_table, refcount_table_size2); |
| ... | ... | @@ -2384,8 +2334,6 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size) |
| 2384 | 2334 | #endif |
| 2385 | 2335 | new_table_size2 = new_table_size * sizeof(uint64_t); |
| 2386 | 2336 | new_table = qemu_mallocz(new_table_size2); |
| 2387 | - if (!new_table) | |
| 2388 | - return -ENOMEM; | |
| 2389 | 2337 | memcpy(new_table, s->refcount_table, |
| 2390 | 2338 | s->refcount_table_size * sizeof(uint64_t)); |
| 2391 | 2339 | for(i = 0; i < s->refcount_table_size; i++) |
| ... | ... | @@ -2556,8 +2504,6 @@ static int check_refcounts_l1(BlockDriverState *bs, |
| 2556 | 2504 | l1_table_offset, l1_size2); |
| 2557 | 2505 | |
| 2558 | 2506 | l1_table = qemu_malloc(l1_size2); |
| 2559 | - if (!l1_table) | |
| 2560 | - goto fail; | |
| 2561 | 2507 | if (bdrv_pread(s->hd, l1_table_offset, |
| 2562 | 2508 | l1_table, l1_size2) != l1_size2) |
| 2563 | 2509 | goto fail; |
| ... | ... | @@ -2566,8 +2512,6 @@ static int check_refcounts_l1(BlockDriverState *bs, |
| 2566 | 2512 | |
| 2567 | 2513 | l2_size = s->l2_size * sizeof(uint64_t); |
| 2568 | 2514 | l2_table = qemu_malloc(l2_size); |
| 2569 | - if (!l2_table) | |
| 2570 | - goto fail; | |
| 2571 | 2515 | for(i = 0; i < l1_size; i++) { |
| 2572 | 2516 | l2_offset = l1_table[i]; |
| 2573 | 2517 | if (l2_offset) { | ... | ... |
block-raw-posix.c
| ... | ... | @@ -533,8 +533,6 @@ static int posix_aio_init(void) |
| 533 | 533 | return 0; |
| 534 | 534 | |
| 535 | 535 | s = qemu_malloc(sizeof(PosixAioState)); |
| 536 | - if (s == NULL) | |
| 537 | - return -ENOMEM; | |
| 538 | 536 | |
| 539 | 537 | sigfillset(&act.sa_mask); |
| 540 | 538 | act.sa_flags = 0; /* do not restart syscalls to interrupt select() */ | ... | ... |
block-vmdk.c
| ... | ... | @@ -276,8 +276,6 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) |
| 276 | 276 | |
| 277 | 277 | /* write RGD */ |
| 278 | 278 | rgd_buf = qemu_malloc(gd_size); |
| 279 | - if (!rgd_buf) | |
| 280 | - goto fail; | |
| 281 | 279 | if (lseek(p_fd, rgd_offset, SEEK_SET) == -1) |
| 282 | 280 | goto fail_rgd; |
| 283 | 281 | if (read(p_fd, rgd_buf, gd_size) != gd_size) |
| ... | ... | @@ -290,8 +288,6 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) |
| 290 | 288 | |
| 291 | 289 | /* write GD */ |
| 292 | 290 | gd_buf = qemu_malloc(gd_size); |
| 293 | - if (!gd_buf) | |
| 294 | - goto fail_rgd; | |
| 295 | 291 | if (lseek(p_fd, gd_offset, SEEK_SET) == -1) |
| 296 | 292 | goto fail_gd; |
| 297 | 293 | if (read(p_fd, gd_buf, gd_size) != gd_size) |
| ... | ... | @@ -430,8 +426,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags) |
| 430 | 426 | /* read the L1 table */ |
| 431 | 427 | l1_size = s->l1_size * sizeof(uint32_t); |
| 432 | 428 | s->l1_table = qemu_malloc(l1_size); |
| 433 | - if (!s->l1_table) | |
| 434 | - goto fail; | |
| 435 | 429 | if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, l1_size) != l1_size) |
| 436 | 430 | goto fail; |
| 437 | 431 | for(i = 0; i < s->l1_size; i++) { |
| ... | ... | @@ -440,8 +434,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags) |
| 440 | 434 | |
| 441 | 435 | if (s->l1_backup_table_offset) { |
| 442 | 436 | s->l1_backup_table = qemu_malloc(l1_size); |
| 443 | - if (!s->l1_backup_table) | |
| 444 | - goto fail; | |
| 445 | 437 | if (bdrv_pread(s->hd, s->l1_backup_table_offset, s->l1_backup_table, l1_size) != l1_size) |
| 446 | 438 | goto fail; |
| 447 | 439 | for(i = 0; i < s->l1_size; i++) { |
| ... | ... | @@ -450,8 +442,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags) |
| 450 | 442 | } |
| 451 | 443 | |
| 452 | 444 | s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint32_t)); |
| 453 | - if (!s->l2_cache) | |
| 454 | - goto fail; | |
| 455 | 445 | return 0; |
| 456 | 446 | fail: |
| 457 | 447 | qemu_free(s->l1_backup_table); | ... | ... |
block-vpc.c
| ... | ... | @@ -196,8 +196,6 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags) |
| 196 | 196 | |
| 197 | 197 | s->max_table_entries = be32_to_cpu(dyndisk_header->max_table_entries); |
| 198 | 198 | s->pagetable = qemu_malloc(s->max_table_entries * 4); |
| 199 | - if (!s->pagetable) | |
| 200 | - goto fail; | |
| 201 | 199 | |
| 202 | 200 | s->bat_offset = be64_to_cpu(dyndisk_header->table_offset); |
| 203 | 201 | if (bdrv_pread(s->hd, s->bat_offset, s->pagetable, |
| ... | ... | @@ -222,8 +220,6 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags) |
| 222 | 220 | |
| 223 | 221 | #ifdef CACHE |
| 224 | 222 | s->pageentry_u8 = qemu_malloc(512); |
| 225 | - if (!s->pageentry_u8) | |
| 226 | - goto fail; | |
| 227 | 223 | s->pageentry_u32 = s->pageentry_u8; |
| 228 | 224 | s->pageentry_u16 = s->pageentry_u8; |
| 229 | 225 | s->last_pagetable = -1; | ... | ... |
block-vvfat.c
| ... | ... | @@ -159,7 +159,7 @@ static inline int array_roll(array_t* array,int index_to,int index_from,int coun |
| 159 | 159 | is=array->item_size; |
| 160 | 160 | from=array->pointer+index_from*is; |
| 161 | 161 | to=array->pointer+index_to*is; |
| 162 | - buf=malloc(is*count); | |
| 162 | + buf=qemu_malloc(is*count); | |
| 163 | 163 | memcpy(buf,from,is*count); |
| 164 | 164 | |
| 165 | 165 | if(index_to<index_from) |
| ... | ... | @@ -725,8 +725,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index) |
| 725 | 725 | if(first_cluster == 0 && (is_dotdot || is_dot)) |
| 726 | 726 | continue; |
| 727 | 727 | |
| 728 | - buffer=(char*)malloc(length); | |
| 729 | - assert(buffer); | |
| 728 | + buffer=(char*)qemu_malloc(length); | |
| 730 | 729 | snprintf(buffer,length,"%s/%s",dirname,entry->d_name); |
| 731 | 730 | |
| 732 | 731 | if(stat(buffer,&st)<0) { |
| ... | ... | @@ -847,8 +846,7 @@ static int init_directories(BDRVVVFATState* s, |
| 847 | 846 | memset(&(s->first_sectors[0]),0,0x40*0x200); |
| 848 | 847 | |
| 849 | 848 | s->cluster_size=s->sectors_per_cluster*0x200; |
| 850 | - s->cluster_buffer=malloc(s->cluster_size); | |
| 851 | - assert(s->cluster_buffer); | |
| 849 | + s->cluster_buffer=qemu_malloc(s->cluster_size); | |
| 852 | 850 | |
| 853 | 851 | /* |
| 854 | 852 | * The formula: sc = spf+1+spf*spc*(512*8/fat_type), |
| ... | ... | @@ -1728,7 +1726,7 @@ static int check_directory_consistency(BDRVVVFATState *s, |
| 1728 | 1726 | int cluster_num, const char* path) |
| 1729 | 1727 | { |
| 1730 | 1728 | int ret = 0; |
| 1731 | - unsigned char* cluster = malloc(s->cluster_size); | |
| 1729 | + unsigned char* cluster = qemu_malloc(s->cluster_size); | |
| 1732 | 1730 | direntry_t* direntries = (direntry_t*)cluster; |
| 1733 | 1731 | mapping_t* mapping = find_mapping_for_cluster(s, cluster_num); |
| 1734 | 1732 | |
| ... | ... | @@ -1869,7 +1867,7 @@ DLOG(checkpoint()); |
| 1869 | 1867 | */ |
| 1870 | 1868 | if (s->fat2 == NULL) { |
| 1871 | 1869 | int size = 0x200 * s->sectors_per_fat; |
| 1872 | - s->fat2 = malloc(size); | |
| 1870 | + s->fat2 = qemu_malloc(size); | |
| 1873 | 1871 | memcpy(s->fat2, s->fat.pointer, size); |
| 1874 | 1872 | } |
| 1875 | 1873 | check = vvfat_read(s->bs, |
| ... | ... | @@ -2211,7 +2209,7 @@ static int commit_one_file(BDRVVVFATState* s, |
| 2211 | 2209 | uint32_t first_cluster = c; |
| 2212 | 2210 | mapping_t* mapping = find_mapping_for_cluster(s, c); |
| 2213 | 2211 | uint32_t size = filesize_of_direntry(direntry); |
| 2214 | - char* cluster = malloc(s->cluster_size); | |
| 2212 | + char* cluster = qemu_malloc(s->cluster_size); | |
| 2215 | 2213 | uint32_t i; |
| 2216 | 2214 | int fd = 0; |
| 2217 | 2215 | |
| ... | ... | @@ -2373,7 +2371,7 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s) |
| 2373 | 2371 | mapping_t* m = find_mapping_for_cluster(s, |
| 2374 | 2372 | begin_of_direntry(d)); |
| 2375 | 2373 | int l = strlen(m->path); |
| 2376 | - char* new_path = malloc(l + diff + 1); | |
| 2374 | + char* new_path = qemu_malloc(l + diff + 1); | |
| 2377 | 2375 | |
| 2378 | 2376 | assert(!strncmp(m->path, mapping->path, l2)); |
| 2379 | 2377 | |
| ... | ... | @@ -2774,7 +2772,7 @@ static int enable_write_target(BDRVVVFATState *s) |
| 2774 | 2772 | |
| 2775 | 2773 | array_init(&(s->commits), sizeof(commit_t)); |
| 2776 | 2774 | |
| 2777 | - s->qcow_filename = malloc(1024); | |
| 2775 | + s->qcow_filename = qemu_malloc(1024); | |
| 2778 | 2776 | get_tmp_filename(s->qcow_filename, 1024); |
| 2779 | 2777 | if (bdrv_create(&bdrv_qcow, |
| 2780 | 2778 | s->qcow_filename, s->sector_count, "fat:", 0) < 0) | ... | ... |
block.c
| ... | ... | @@ -151,8 +151,6 @@ BlockDriverState *bdrv_new(const char *device_name) |
| 151 | 151 | BlockDriverState **pbs, *bs; |
| 152 | 152 | |
| 153 | 153 | bs = qemu_mallocz(sizeof(BlockDriverState)); |
| 154 | - if(!bs) | |
| 155 | - return NULL; | |
| 156 | 154 | pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); |
| 157 | 155 | if (device_name[0] != '\0') { |
| 158 | 156 | /* insert at the end */ |
| ... | ... | @@ -395,8 +393,6 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, |
| 395 | 393 | } |
| 396 | 394 | bs->drv = drv; |
| 397 | 395 | bs->opaque = qemu_mallocz(drv->instance_size); |
| 398 | - if (bs->opaque == NULL && drv->instance_size > 0) | |
| 399 | - return -1; | |
| 400 | 396 | /* Note: for compatibility, we open disk image files as RDWR, and |
| 401 | 397 | RDONLY as fallback */ |
| 402 | 398 | if (!(flags & BDRV_O_FILE)) |
| ... | ... | @@ -1498,8 +1494,6 @@ void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb, |
| 1498 | 1494 | drv->free_aiocb = acb->next; |
| 1499 | 1495 | } else { |
| 1500 | 1496 | acb = qemu_mallocz(drv->aiocb_size); |
| 1501 | - if (!acb) | |
| 1502 | - return NULL; | |
| 1503 | 1497 | } |
| 1504 | 1498 | acb->bs = bs; |
| 1505 | 1499 | acb->cb = cb; | ... | ... |