Revision 7267c094 hw/9pfs/virtio-9p.c

b/hw/9pfs/virtio-9p.c
239 239

  
240 240
static void v9fs_string_free(V9fsString *str)
241 241
{
242
    qemu_free(str->data);
242
    g_free(str->data);
243 243
    str->data = NULL;
244 244
    str->size = 0;
245 245
}
......
338 338
    }
339 339

  
340 340
alloc_print:
341
    *strp = qemu_malloc((len + 1) * sizeof(**strp));
341
    *strp = g_malloc((len + 1) * sizeof(**strp));
342 342

  
343 343
    return vsprintf(*strp, fmt, ap);
344 344
}
......
408 408
        return NULL;
409 409
    }
410 410

  
411
    f = qemu_mallocz(sizeof(V9fsFidState));
411
    f = g_malloc0(sizeof(V9fsFidState));
412 412

  
413 413
    f->fid = fid;
414 414
    f->fid_type = P9_FID_NONE;
......
448 448
    v9fs_string_free(&fidp->fs.xattr.name);
449 449
free_value:
450 450
    if (fidp->fs.xattr.value) {
451
        qemu_free(fidp->fs.xattr.value);
451
        g_free(fidp->fs.xattr.value);
452 452
    }
453 453
    return retval;
454 454
}
......
479 479
        retval = v9fs_xattr_fid_clunk(s, fidp);
480 480
    }
481 481
    v9fs_string_free(&fidp->path);
482
    qemu_free(fidp);
482
    g_free(fidp);
483 483

  
484 484
    return retval;
485 485
}
......
685 685
            V9fsString *str = va_arg(ap, V9fsString *);
686 686
            offset += pdu_unmarshal(pdu, offset, "w", &str->size);
687 687
            /* FIXME: sanity check str->size */
688
            str->data = qemu_malloc(str->size + 1);
688
            str->data = g_malloc(str->size + 1);
689 689
            offset += pdu_unpack(str->data, pdu, offset, str->size);
690 690
            str->data[str->size] = 0;
691 691
            break;
......
1209 1209
out:
1210 1210
    complete_pdu(s, vs->pdu, err);
1211 1211
    v9fs_stat_free(&vs->v9stat);
1212
    qemu_free(vs);
1212
    g_free(vs);
1213 1213
}
1214 1214

  
1215 1215
static void v9fs_stat(void *opaque)
......
1220 1220
    V9fsStatState *vs;
1221 1221
    ssize_t err = 0;
1222 1222

  
1223
    vs = qemu_malloc(sizeof(*vs));
1223
    vs = g_malloc(sizeof(*vs));
1224 1224
    vs->pdu = pdu;
1225 1225
    vs->offset = 7;
1226 1226

  
......
1241 1241
out:
1242 1242
    complete_pdu(s, vs->pdu, err);
1243 1243
    v9fs_stat_free(&vs->v9stat);
1244
    qemu_free(vs);
1244
    g_free(vs);
1245 1245
}
1246 1246

  
1247 1247
static void v9fs_getattr(void *opaque)
......
1379 1379
            v9fs_string_free(&vs->wnames[vs->name_idx]);
1380 1380
        }
1381 1381

  
1382
        qemu_free(vs->wnames);
1383
        qemu_free(vs->qids);
1382
        g_free(vs->wnames);
1383
        g_free(vs->qids);
1384 1384
    }
1385 1385
}
1386 1386

  
......
1463 1463
    int err = 0;
1464 1464
    int i;
1465 1465

  
1466
    vs = qemu_malloc(sizeof(*vs));
1466
    vs = g_malloc(sizeof(*vs));
1467 1467
    vs->pdu = pdu;
1468 1468
    vs->wnames = NULL;
1469 1469
    vs->qids = NULL;
......
1473 1473
                                            &newfid, &vs->nwnames);
1474 1474

  
1475 1475
    if (vs->nwnames && vs->nwnames <= P9_MAXWELEM) {
1476
        vs->wnames = qemu_mallocz(sizeof(vs->wnames[0]) * vs->nwnames);
1476
        vs->wnames = g_malloc0(sizeof(vs->wnames[0]) * vs->nwnames);
1477 1477

  
1478
        vs->qids = qemu_mallocz(sizeof(vs->qids[0]) * vs->nwnames);
1478
        vs->qids = g_malloc0(sizeof(vs->qids[0]) * vs->nwnames);
1479 1479

  
1480 1480
        for (i = 0; i < vs->nwnames; i++) {
1481 1481
            vs->offset += pdu_unmarshal(vs->pdu, vs->offset, "s",
......
1568 1568
    err = vs->offset;
1569 1569
out:
1570 1570
    complete_pdu(s, vs->pdu, err);
1571
    qemu_free(vs);
1571
    g_free(vs);
1572 1572

  
1573 1573
}
1574 1574

  
......
1578 1578
    vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, vs->iounit);
1579 1579
    err = vs->offset;
1580 1580
    complete_pdu(s, vs->pdu, err);
1581
    qemu_free(vs);
1581
    g_free(vs);
1582 1582
}
1583 1583

  
1584 1584
static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err)
......
1593 1593
    return;
1594 1594
out:
1595 1595
    complete_pdu(s, vs->pdu, err);
1596
    qemu_free(vs);
1596
    g_free(vs);
1597 1597
}
1598 1598

  
1599 1599
static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
......
1625 1625
    return;
1626 1626
out:
1627 1627
    complete_pdu(s, vs->pdu, err);
1628
    qemu_free(vs);
1628
    g_free(vs);
1629 1629
}
1630 1630

  
1631 1631
static void v9fs_open(void *opaque)
......
1636 1636
    V9fsOpenState *vs;
1637 1637
    ssize_t err = 0;
1638 1638

  
1639
    vs = qemu_malloc(sizeof(*vs));
1639
    vs = g_malloc(sizeof(*vs));
1640 1640
    vs->pdu = pdu;
1641 1641
    vs->offset = 7;
1642 1642
    vs->mode = 0;
......
1661 1661
    return;
1662 1662
out:
1663 1663
    complete_pdu(s, pdu, err);
1664
    qemu_free(vs);
1664
    g_free(vs);
1665 1665
}
1666 1666

  
1667 1667
static void v9fs_post_lcreate(V9fsState *s, V9fsLcreateState *vs, int err)
......
1683 1683
    complete_pdu(s, vs->pdu, err);
1684 1684
    v9fs_string_free(&vs->name);
1685 1685
    v9fs_string_free(&vs->fullname);
1686
    qemu_free(vs);
1686
    g_free(vs);
1687 1687
}
1688 1688

  
1689 1689
static void v9fs_lcreate_post_get_iounit(V9fsState *s, V9fsLcreateState *vs,
......
1724 1724
    V9fsLcreateState *vs;
1725 1725
    ssize_t err = 0;
1726 1726

  
1727
    vs = qemu_malloc(sizeof(*vs));
1727
    vs = g_malloc(sizeof(*vs));
1728 1728
    vs->pdu = pdu;
1729 1729
    vs->offset = 7;
1730 1730

  
......
1753 1753
out:
1754 1754
    complete_pdu(s, vs->pdu, err);
1755 1755
    v9fs_string_free(&vs->name);
1756
    qemu_free(vs);
1756
    g_free(vs);
1757 1757
}
1758 1758

  
1759 1759
static void v9fs_post_do_fsync(V9fsState *s, V9fsPDU *pdu, int err)
......
1820 1820
    complete_pdu(s, vs->pdu, err);
1821 1821
    v9fs_stat_free(&vs->v9stat);
1822 1822
    v9fs_string_free(&vs->name);
1823
    qemu_free(vs);
1823
    g_free(vs);
1824 1824
    return;
1825 1825
}
1826 1826

  
......
1874 1874
    vs->offset += vs->count;
1875 1875
    err = vs->offset;
1876 1876
    complete_pdu(s, vs->pdu, err);
1877
    qemu_free(vs);
1877
    g_free(vs);
1878 1878
    return;
1879 1879
}
1880 1880

  
......
1925 1925

  
1926 1926
out:
1927 1927
    complete_pdu(s, vs->pdu, err);
1928
    qemu_free(vs);
1928
    g_free(vs);
1929 1929
}
1930 1930

  
1931 1931
static void v9fs_xattr_read(V9fsState *s, V9fsReadState *vs)
......
1950 1950
                           read_count);
1951 1951
    err = vs->offset;
1952 1952
    complete_pdu(s, vs->pdu, err);
1953
    qemu_free(vs);
1953
    g_free(vs);
1954 1954
}
1955 1955

  
1956 1956
static void v9fs_read(void *opaque)
......
1961 1961
    V9fsReadState *vs;
1962 1962
    ssize_t err = 0;
1963 1963

  
1964
    vs = qemu_malloc(sizeof(*vs));
1964
    vs = g_malloc(sizeof(*vs));
1965 1965
    vs->pdu = pdu;
1966 1966
    vs->offset = 7;
1967 1967
    vs->total = 0;
......
2006 2006
    }
2007 2007
out:
2008 2008
    complete_pdu(s, pdu, err);
2009
    qemu_free(vs);
2009
    g_free(vs);
2010 2010
}
2011 2011

  
2012 2012
static size_t v9fs_readdir_data_size(V9fsString *name)
......
2138 2138
    err = vs->offset;
2139 2139
out:
2140 2140
    complete_pdu(s, vs->pdu, err);
2141
    qemu_free(vs);
2141
    g_free(vs);
2142 2142
}
2143 2143

  
2144 2144
static void v9fs_xattr_write(V9fsState *s, V9fsWriteState *vs)
......
2180 2180
    }
2181 2181
out:
2182 2182
    complete_pdu(s, vs->pdu, err);
2183
    qemu_free(vs);
2183
    g_free(vs);
2184 2184
}
2185 2185

  
2186 2186
static void v9fs_write(void *opaque)
......
2191 2191
    V9fsWriteState *vs;
2192 2192
    ssize_t err;
2193 2193

  
2194
    vs = qemu_malloc(sizeof(*vs));
2194
    vs = g_malloc(sizeof(*vs));
2195 2195

  
2196 2196
    vs->pdu = pdu;
2197 2197
    vs->offset = 7;
......
2235 2235
    return;
2236 2236
out:
2237 2237
    complete_pdu(s, vs->pdu, err);
2238
    qemu_free(vs);
2238
    g_free(vs);
2239 2239
}
2240 2240

  
2241 2241
static void v9fs_create_post_getiounit(V9fsState *s, V9fsCreateState *vs)
......
2251 2251
    v9fs_string_free(&vs->name);
2252 2252
    v9fs_string_free(&vs->extension);
2253 2253
    v9fs_string_free(&vs->fullname);
2254
    qemu_free(vs);
2254
    g_free(vs);
2255 2255
}
2256 2256

  
2257 2257
static void v9fs_post_create(V9fsState *s, V9fsCreateState *vs, int err)
......
2266 2266
    v9fs_string_free(&vs->name);
2267 2267
    v9fs_string_free(&vs->extension);
2268 2268
    v9fs_string_free(&vs->fullname);
2269
    qemu_free(vs);
2269
    g_free(vs);
2270 2270
}
2271 2271

  
2272 2272
static void v9fs_create_post_perms(V9fsState *s, V9fsCreateState *vs, int err)
......
2426 2426
    V9fsCreateState *vs;
2427 2427
    int err = 0;
2428 2428

  
2429
    vs = qemu_malloc(sizeof(*vs));
2429
    vs = g_malloc(sizeof(*vs));
2430 2430
    vs->pdu = pdu;
2431 2431
    vs->offset = 7;
2432 2432

  
......
2452 2452
    complete_pdu(s, vs->pdu, err);
2453 2453
    v9fs_string_free(&vs->name);
2454 2454
    v9fs_string_free(&vs->extension);
2455
    qemu_free(vs);
2455
    g_free(vs);
2456 2456
}
2457 2457

  
2458 2458
static void v9fs_post_symlink(V9fsState *s, V9fsSymlinkState *vs, int err)
......
2468 2468
    v9fs_string_free(&vs->name);
2469 2469
    v9fs_string_free(&vs->symname);
2470 2470
    v9fs_string_free(&vs->fullname);
2471
    qemu_free(vs);
2471
    g_free(vs);
2472 2472
}
2473 2473

  
2474 2474
static void v9fs_symlink_post_do_symlink(V9fsState *s, V9fsSymlinkState *vs,
......
2491 2491
    int err = 0;
2492 2492
    gid_t gid;
2493 2493

  
2494
    vs = qemu_malloc(sizeof(*vs));
2494
    vs = g_malloc(sizeof(*vs));
2495 2495
    vs->pdu = pdu;
2496 2496
    vs->offset = 7;
2497 2497

  
......
2517 2517
    complete_pdu(s, vs->pdu, err);
2518 2518
    v9fs_string_free(&vs->name);
2519 2519
    v9fs_string_free(&vs->symname);
2520
    qemu_free(vs);
2520
    g_free(vs);
2521 2521
}
2522 2522

  
2523 2523
static void v9fs_flush(void *opaque)
......
2605 2605
out:
2606 2606
    v9fs_stat_free(&vs->v9stat);
2607 2607
    complete_pdu(s, vs->pdu, err);
2608
    qemu_free(vs);
2608
    g_free(vs);
2609 2609
}
2610 2610

  
2611 2611
static void v9fs_wstat_post_rename(V9fsState *s, V9fsWstatState *vs, int err)
......
2624 2624
out:
2625 2625
    v9fs_stat_free(&vs->v9stat);
2626 2626
    complete_pdu(s, vs->pdu, err);
2627
    qemu_free(vs);
2627
    g_free(vs);
2628 2628
}
2629 2629

  
2630 2630
static int v9fs_complete_rename(V9fsState *s, V9fsFidState *fidp,
......
2643 2643
        }
2644 2644
        BUG_ON(dirfidp->fid_type != P9_FID_NONE);
2645 2645

  
2646
        new_name = qemu_mallocz(dirfidp->path.size + name->size + 2);
2646
        new_name = g_malloc0(dirfidp->path.size + name->size + 2);
2647 2647

  
2648 2648
        strcpy(new_name, dirfidp->path.data);
2649 2649
        strcat(new_name, "/");
......
2656 2656
        } else {
2657 2657
            end = old_name;
2658 2658
        }
2659
        new_name = qemu_mallocz(end - old_name + name->size + 1);
2659
        new_name = g_malloc0(end - old_name + name->size + 1);
2660 2660

  
2661 2661
        strncat(new_name, old_name, end - old_name);
2662 2662
        strncat(new_name + (end - old_name), name->data, name->size);
......
2710 2710
out:
2711 2711
    v9fs_stat_free(&vs->v9stat);
2712 2712
    complete_pdu(s, vs->pdu, err);
2713
    qemu_free(vs);
2713
    g_free(vs);
2714 2714
}
2715 2715

  
2716 2716
static void v9fs_rename(void *opaque)
......
2760 2760
out:
2761 2761
    v9fs_stat_free(&vs->v9stat);
2762 2762
    complete_pdu(s, vs->pdu, err);
2763
    qemu_free(vs);
2763
    g_free(vs);
2764 2764
}
2765 2765

  
2766 2766
static void v9fs_wstat_post_chmod(V9fsState *s, V9fsWstatState *vs, int err)
......
2795 2795
out:
2796 2796
    v9fs_stat_free(&vs->v9stat);
2797 2797
    complete_pdu(s, vs->pdu, err);
2798
    qemu_free(vs);
2798
    g_free(vs);
2799 2799
}
2800 2800

  
2801 2801
static void v9fs_wstat_post_fsync(V9fsState *s, V9fsWstatState *vs, int err)
......
2805 2805
    }
2806 2806
    v9fs_stat_free(&vs->v9stat);
2807 2807
    complete_pdu(s, vs->pdu, err);
2808
    qemu_free(vs);
2808
    g_free(vs);
2809 2809
}
2810 2810

  
2811 2811
static void v9fs_wstat_post_lstat(V9fsState *s, V9fsWstatState *vs, int err)
......
2836 2836
out:
2837 2837
    v9fs_stat_free(&vs->v9stat);
2838 2838
    complete_pdu(s, vs->pdu, err);
2839
    qemu_free(vs);
2839
    g_free(vs);
2840 2840
}
2841 2841

  
2842 2842
static void v9fs_wstat(void *opaque)
......
2847 2847
    V9fsWstatState *vs;
2848 2848
    int err = 0;
2849 2849

  
2850
    vs = qemu_malloc(sizeof(*vs));
2850
    vs = g_malloc(sizeof(*vs));
2851 2851
    vs->pdu = pdu;
2852 2852
    vs->offset = 7;
2853 2853

  
......
2878 2878
out:
2879 2879
    v9fs_stat_free(&vs->v9stat);
2880 2880
    complete_pdu(s, vs->pdu, err);
2881
    qemu_free(vs);
2881
    g_free(vs);
2882 2882
}
2883 2883

  
2884 2884
static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf)
......
3014 3014
    int32_t fid, err = 0;
3015 3015
    V9fsLockState *vs;
3016 3016

  
3017
    vs = qemu_mallocz(sizeof(*vs));
3017
    vs = g_malloc0(sizeof(*vs));
3018 3018
    vs->pdu = pdu;
3019 3019
    vs->offset = 7;
3020 3020

  
3021
    vs->flock = qemu_malloc(sizeof(*vs->flock));
3021
    vs->flock = g_malloc(sizeof(*vs->flock));
3022 3022
    pdu_unmarshal(vs->pdu, vs->offset, "dbdqqds", &fid, &vs->flock->type,
3023 3023
                &vs->flock->flags, &vs->flock->start, &vs->flock->length,
3024 3024
                            &vs->flock->proc_id, &vs->flock->client_id);
......
3045 3045
out:
3046 3046
    vs->offset += pdu_marshal(vs->pdu, vs->offset, "b", vs->status);
3047 3047
    complete_pdu(s, vs->pdu, err);
3048
    qemu_free(vs->flock);
3049
    qemu_free(vs);
3048
    g_free(vs->flock);
3049
    g_free(vs);
3050 3050
}
3051 3051

  
3052 3052
/*
......
3061 3061
    int32_t fid, err = 0;
3062 3062
    V9fsGetlockState *vs;
3063 3063

  
3064
    vs = qemu_mallocz(sizeof(*vs));
3064
    vs = g_malloc0(sizeof(*vs));
3065 3065
    vs->pdu = pdu;
3066 3066
    vs->offset = 7;
3067 3067

  
3068
    vs->glock = qemu_malloc(sizeof(*vs->glock));
3068
    vs->glock = g_malloc(sizeof(*vs->glock));
3069 3069
    pdu_unmarshal(vs->pdu, vs->offset, "dbqqds", &fid, &vs->glock->type,
3070 3070
                &vs->glock->start, &vs->glock->length, &vs->glock->proc_id,
3071 3071
		&vs->glock->client_id);
......
3087 3087
		&vs->glock->client_id);
3088 3088
out:
3089 3089
    complete_pdu(s, vs->pdu, err);
3090
    qemu_free(vs->glock);
3091
    qemu_free(vs);
3090
    g_free(vs->glock);
3091
    g_free(vs);
3092 3092
}
3093 3093

  
3094 3094
static void v9fs_mkdir(void *opaque)
......
3171 3171
        xattr_fidp->fid_type = P9_FID_XATTR;
3172 3172
        xattr_fidp->fs.xattr.copied_len = -1;
3173 3173
        if (size) {
3174
            xattr_fidp->fs.xattr.value = qemu_malloc(size);
3174
            xattr_fidp->fs.xattr.value = g_malloc(size);
3175 3175
            err = v9fs_co_llistxattr(s, &xattr_fidp->path,
3176 3176
                                     xattr_fidp->fs.xattr.value,
3177 3177
                                     xattr_fidp->fs.xattr.len);
......
3201 3201
        xattr_fidp->fid_type = P9_FID_XATTR;
3202 3202
        xattr_fidp->fs.xattr.copied_len = -1;
3203 3203
        if (size) {
3204
            xattr_fidp->fs.xattr.value = qemu_malloc(size);
3204
            xattr_fidp->fs.xattr.value = g_malloc(size);
3205 3205
            err = v9fs_co_lgetxattr(s, &xattr_fidp->path,
3206 3206
                                    &name, xattr_fidp->fs.xattr.value,
3207 3207
                                    xattr_fidp->fs.xattr.len);
......
3248 3248
    v9fs_string_init(&xattr_fidp->fs.xattr.name);
3249 3249
    v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name);
3250 3250
    if (size) {
3251
        xattr_fidp->fs.xattr.value = qemu_malloc(size);
3251
        xattr_fidp->fs.xattr.value = g_malloc(size);
3252 3252
    } else {
3253 3253
        xattr_fidp->fs.xattr.value = NULL;
3254 3254
    }

Also available in: Unified diff