Revision 7267c094 block/qcow2.c

b/block/qcow2.c
216 216
    }
217 217
    s->l1_table_offset = header.l1_table_offset;
218 218
    if (s->l1_size > 0) {
219
        s->l1_table = qemu_mallocz(
219
        s->l1_table = g_malloc0(
220 220
            align_offset(s->l1_size * sizeof(uint64_t), 512));
221 221
        ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table,
222 222
                         s->l1_size * sizeof(uint64_t));
......
234 234
    s->refcount_block_cache = qcow2_cache_create(bs, REFCOUNT_CACHE_SIZE,
235 235
        writethrough);
236 236

  
237
    s->cluster_cache = qemu_malloc(s->cluster_size);
237
    s->cluster_cache = g_malloc(s->cluster_size);
238 238
    /* one more sector for decompressed data alignment */
239
    s->cluster_data = qemu_malloc(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size
239
    s->cluster_data = g_malloc(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size
240 240
                                  + 512);
241 241
    s->cluster_cache_offset = -1;
242 242

  
......
287 287
 fail:
288 288
    qcow2_free_snapshots(bs);
289 289
    qcow2_refcount_close(bs);
290
    qemu_free(s->l1_table);
290
    g_free(s->l1_table);
291 291
    if (s->l2_table_cache) {
292 292
        qcow2_cache_destroy(bs, s->l2_table_cache);
293 293
    }
294
    qemu_free(s->cluster_cache);
295
    qemu_free(s->cluster_data);
294
    g_free(s->cluster_cache);
295
    g_free(s->cluster_data);
296 296
    return ret;
297 297
}
298 298

  
......
501 501
             */
502 502
            if (!acb->cluster_data) {
503 503
                acb->cluster_data =
504
                    qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size);
504
                    g_malloc0(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size);
505 505
            }
506 506

  
507 507
            assert(acb->cur_nr_sectors <=
......
636 636

  
637 637
    if (s->crypt_method) {
638 638
        if (!acb->cluster_data) {
639
            acb->cluster_data = qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS *
639
            acb->cluster_data = g_malloc0(QCOW_MAX_CRYPT_CLUSTERS *
640 640
                                             s->cluster_size);
641 641
        }
642 642

  
......
691 691
static void qcow2_close(BlockDriverState *bs)
692 692
{
693 693
    BDRVQcowState *s = bs->opaque;
694
    qemu_free(s->l1_table);
694
    g_free(s->l1_table);
695 695

  
696 696
    qcow2_cache_flush(bs, s->l2_table_cache);
697 697
    qcow2_cache_flush(bs, s->refcount_block_cache);
......
699 699
    qcow2_cache_destroy(bs, s->l2_table_cache);
700 700
    qcow2_cache_destroy(bs, s->refcount_block_cache);
701 701

  
702
    qemu_free(s->cluster_cache);
703
    qemu_free(s->cluster_data);
702
    g_free(s->cluster_cache);
703
    g_free(s->cluster_data);
704 704
    qcow2_refcount_close(bs);
705 705
}
706 706

  
......
923 923
    }
924 924

  
925 925
    /* Write an empty refcount table */
926
    refcount_table = qemu_mallocz(cluster_size);
926
    refcount_table = g_malloc0(cluster_size);
927 927
    ret = bdrv_pwrite(bs, cluster_size, refcount_table, cluster_size);
928
    qemu_free(refcount_table);
928
    g_free(refcount_table);
929 929

  
930 930
    if (ret < 0) {
931 931
        goto out;
......
1117 1117
    if (nb_sectors != s->cluster_sectors)
1118 1118
        return -EINVAL;
1119 1119

  
1120
    out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
1120
    out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
1121 1121

  
1122 1122
    /* best compression, small window, no zlib header */
1123 1123
    memset(&strm, 0, sizeof(strm));
......
1125 1125
                       Z_DEFLATED, -12,
1126 1126
                       9, Z_DEFAULT_STRATEGY);
1127 1127
    if (ret != 0) {
1128
        qemu_free(out_buf);
1128
        g_free(out_buf);
1129 1129
        return -1;
1130 1130
    }
1131 1131

  
......
1136 1136

  
1137 1137
    ret = deflate(&strm, Z_FINISH);
1138 1138
    if (ret != Z_STREAM_END && ret != Z_OK) {
1139
        qemu_free(out_buf);
1139
        g_free(out_buf);
1140 1140
        deflateEnd(&strm);
1141 1141
        return -1;
1142 1142
    }
......
1155 1155
        cluster_offset &= s->cluster_offset_mask;
1156 1156
        BLKDBG_EVENT(bs->file, BLKDBG_WRITE_COMPRESSED);
1157 1157
        if (bdrv_pwrite(bs->file, cluster_offset, out_buf, out_len) != out_len) {
1158
            qemu_free(out_buf);
1158
            g_free(out_buf);
1159 1159
            return -1;
1160 1160
        }
1161 1161
    }
1162 1162

  
1163
    qemu_free(out_buf);
1163
    g_free(out_buf);
1164 1164
    return 0;
1165 1165
}
1166 1166

  

Also available in: Unified diff