@@ -661,27 +661,24 @@ void WASI::FdPread(const FunctionCallbackInfo<Value>& args) {
661
661
iovs_ptr,
662
662
iovs_len * UVWASI_SERDES_SIZE_iovec_t);
663
663
CHECK_BOUNDS_OR_RETURN (args, mem_size, nread_ptr, UVWASI_SERDES_SIZE_size_t);
664
- uvwasi_iovec_t * iovs = UncheckedCalloc <uvwasi_iovec_t >(iovs_len);
664
+ std::vector <uvwasi_iovec_t > iovs (iovs_len);
665
665
uvwasi_errno_t err;
666
666
667
- if (iovs == nullptr ) {
668
- args.GetReturnValue ().Set (UVWASI_ENOMEM);
669
- return ;
670
- }
671
-
672
- err = uvwasi_serdes_readv_iovec_t (memory, mem_size, iovs_ptr, iovs, iovs_len);
667
+ err = uvwasi_serdes_readv_iovec_t (memory,
668
+ mem_size,
669
+ iovs_ptr,
670
+ iovs.data (),
671
+ iovs_len);
673
672
if (err != UVWASI_ESUCCESS) {
674
- free (iovs);
675
673
args.GetReturnValue ().Set (err);
676
674
return ;
677
675
}
678
676
679
677
uvwasi_size_t nread;
680
- err = uvwasi_fd_pread (&wasi->uvw_ , fd, iovs, iovs_len, offset, &nread);
678
+ err = uvwasi_fd_pread (&wasi->uvw_ , fd, iovs. data () , iovs_len, offset, &nread);
681
679
if (err == UVWASI_ESUCCESS)
682
680
uvwasi_serdes_write_size_t (memory, nread_ptr, nread);
683
681
684
- free (iovs);
685
682
args.GetReturnValue ().Set (err);
686
683
}
687
684
@@ -764,31 +761,29 @@ void WASI::FdPwrite(const FunctionCallbackInfo<Value>& args) {
764
761
mem_size,
765
762
nwritten_ptr,
766
763
UVWASI_SERDES_SIZE_size_t);
767
- uvwasi_ciovec_t * iovs = UncheckedCalloc <uvwasi_ciovec_t >(iovs_len);
764
+ std::vector <uvwasi_ciovec_t > iovs (iovs_len);
768
765
uvwasi_errno_t err;
769
766
770
- if (iovs == nullptr ) {
771
- args.GetReturnValue ().Set (UVWASI_ENOMEM);
772
- return ;
773
- }
774
-
775
767
err = uvwasi_serdes_readv_ciovec_t (memory,
776
768
mem_size,
777
769
iovs_ptr,
778
- iovs,
770
+ iovs. data () ,
779
771
iovs_len);
780
772
if (err != UVWASI_ESUCCESS) {
781
- free (iovs);
782
773
args.GetReturnValue ().Set (err);
783
774
return ;
784
775
}
785
776
786
777
uvwasi_size_t nwritten;
787
- err = uvwasi_fd_pwrite (&wasi->uvw_ , fd, iovs, iovs_len, offset, &nwritten);
778
+ err = uvwasi_fd_pwrite (&wasi->uvw_ ,
779
+ fd,
780
+ iovs.data (),
781
+ iovs_len,
782
+ offset,
783
+ &nwritten);
788
784
if (err == UVWASI_ESUCCESS)
789
785
uvwasi_serdes_write_size_t (memory, nwritten_ptr, nwritten);
790
786
791
- free (iovs);
792
787
args.GetReturnValue ().Set (err);
793
788
}
794
789
@@ -814,27 +809,24 @@ void WASI::FdRead(const FunctionCallbackInfo<Value>& args) {
814
809
iovs_ptr,
815
810
iovs_len * UVWASI_SERDES_SIZE_iovec_t);
816
811
CHECK_BOUNDS_OR_RETURN (args, mem_size, nread_ptr, UVWASI_SERDES_SIZE_size_t);
817
- uvwasi_iovec_t * iovs = UncheckedCalloc <uvwasi_iovec_t >(iovs_len);
812
+ std::vector <uvwasi_iovec_t > iovs (iovs_len);
818
813
uvwasi_errno_t err;
819
814
820
- if (iovs == nullptr ) {
821
- args.GetReturnValue ().Set (UVWASI_ENOMEM);
822
- return ;
823
- }
824
-
825
- err = uvwasi_serdes_readv_iovec_t (memory, mem_size, iovs_ptr, iovs, iovs_len);
815
+ err = uvwasi_serdes_readv_iovec_t (memory,
816
+ mem_size,
817
+ iovs_ptr,
818
+ iovs.data (),
819
+ iovs_len);
826
820
if (err != UVWASI_ESUCCESS) {
827
- free (iovs);
828
821
args.GetReturnValue ().Set (err);
829
822
return ;
830
823
}
831
824
832
825
uvwasi_size_t nread;
833
- err = uvwasi_fd_read (&wasi->uvw_ , fd, iovs, iovs_len, &nread);
826
+ err = uvwasi_fd_read (&wasi->uvw_ , fd, iovs. data () , iovs_len, &nread);
834
827
if (err == UVWASI_ESUCCESS)
835
828
uvwasi_serdes_write_size_t (memory, nread_ptr, nread);
836
829
837
- free (iovs);
838
830
args.GetReturnValue ().Set (err);
839
831
}
840
832
@@ -996,31 +988,24 @@ void WASI::FdWrite(const FunctionCallbackInfo<Value>& args) {
996
988
mem_size,
997
989
nwritten_ptr,
998
990
UVWASI_SERDES_SIZE_size_t);
999
- uvwasi_ciovec_t * iovs = UncheckedCalloc <uvwasi_ciovec_t >(iovs_len);
991
+ std::vector <uvwasi_ciovec_t > iovs (iovs_len);
1000
992
uvwasi_errno_t err;
1001
993
1002
- if (iovs == nullptr ) {
1003
- args.GetReturnValue ().Set (UVWASI_ENOMEM);
1004
- return ;
1005
- }
1006
-
1007
994
err = uvwasi_serdes_readv_ciovec_t (memory,
1008
995
mem_size,
1009
996
iovs_ptr,
1010
- iovs,
997
+ iovs. data () ,
1011
998
iovs_len);
1012
999
if (err != UVWASI_ESUCCESS) {
1013
- free (iovs);
1014
1000
args.GetReturnValue ().Set (err);
1015
1001
return ;
1016
1002
}
1017
1003
1018
1004
uvwasi_size_t nwritten;
1019
- err = uvwasi_fd_write (&wasi->uvw_ , fd, iovs, iovs_len, &nwritten);
1005
+ err = uvwasi_fd_write (&wasi->uvw_ , fd, iovs. data () , iovs_len, &nwritten);
1020
1006
if (err == UVWASI_ESUCCESS)
1021
1007
uvwasi_serdes_write_size_t (memory, nwritten_ptr, nwritten);
1022
1008
1023
- free (iovs);
1024
1009
args.GetReturnValue ().Set (err);
1025
1010
}
1026
1011
@@ -1435,21 +1420,8 @@ void WASI::PollOneoff(const FunctionCallbackInfo<Value>& args) {
1435
1420
mem_size,
1436
1421
nevents_ptr,
1437
1422
UVWASI_SERDES_SIZE_size_t);
1438
- uvwasi_subscription_t * in =
1439
- UncheckedCalloc<uvwasi_subscription_t >(nsubscriptions);
1440
-
1441
- if (in == nullptr ) {
1442
- args.GetReturnValue ().Set (UVWASI_ENOMEM);
1443
- return ;
1444
- }
1445
-
1446
- uvwasi_event_t * out = UncheckedCalloc<uvwasi_event_t >(nsubscriptions);
1447
-
1448
- if (out == nullptr ) {
1449
- free (in);
1450
- args.GetReturnValue ().Set (UVWASI_ENOMEM);
1451
- return ;
1452
- }
1423
+ std::vector<uvwasi_subscription_t > in (nsubscriptions);
1424
+ std::vector<uvwasi_event_t > out (nsubscriptions);
1453
1425
1454
1426
for (uint32_t i = 0 ; i < nsubscriptions; ++i) {
1455
1427
uvwasi_serdes_read_subscription_t (memory, in_ptr, &in[i]);
@@ -1458,8 +1430,8 @@ void WASI::PollOneoff(const FunctionCallbackInfo<Value>& args) {
1458
1430
1459
1431
uvwasi_size_t nevents;
1460
1432
uvwasi_errno_t err = uvwasi_poll_oneoff (&wasi->uvw_ ,
1461
- in,
1462
- out,
1433
+ in. data () ,
1434
+ out. data () ,
1463
1435
nsubscriptions,
1464
1436
&nevents);
1465
1437
if (err == UVWASI_ESUCCESS) {
@@ -1471,8 +1443,6 @@ void WASI::PollOneoff(const FunctionCallbackInfo<Value>& args) {
1471
1443
}
1472
1444
}
1473
1445
1474
- free (in);
1475
- free (out);
1476
1446
args.GetReturnValue ().Set (err);
1477
1447
}
1478
1448
@@ -1563,20 +1533,13 @@ void WASI::SockRecv(const FunctionCallbackInfo<Value>& args) {
1563
1533
ri_data_len * UVWASI_SERDES_SIZE_iovec_t);
1564
1534
CHECK_BOUNDS_OR_RETURN (args, mem_size, ro_datalen_ptr, 4 );
1565
1535
CHECK_BOUNDS_OR_RETURN (args, mem_size, ro_flags_ptr, 4 );
1566
- uvwasi_iovec_t * ri_data = UncheckedCalloc<uvwasi_iovec_t >(ri_data_len);
1567
-
1568
- if (ri_data == nullptr ) {
1569
- args.GetReturnValue ().Set (UVWASI_ENOMEM);
1570
- return ;
1571
- }
1572
-
1536
+ std::vector<uvwasi_iovec_t > ri_data (ri_data_len);
1573
1537
uvwasi_errno_t err = uvwasi_serdes_readv_iovec_t (memory,
1574
1538
mem_size,
1575
1539
ri_data_ptr,
1576
- ri_data,
1540
+ ri_data. data () ,
1577
1541
ri_data_len);
1578
1542
if (err != UVWASI_ESUCCESS) {
1579
- free (ri_data);
1580
1543
args.GetReturnValue ().Set (err);
1581
1544
return ;
1582
1545
}
@@ -1585,7 +1548,7 @@ void WASI::SockRecv(const FunctionCallbackInfo<Value>& args) {
1585
1548
uvwasi_roflags_t ro_flags;
1586
1549
err = uvwasi_sock_recv (&wasi->uvw_ ,
1587
1550
sock,
1588
- ri_data,
1551
+ ri_data. data () ,
1589
1552
ri_data_len,
1590
1553
ri_flags,
1591
1554
&ro_datalen,
@@ -1595,7 +1558,6 @@ void WASI::SockRecv(const FunctionCallbackInfo<Value>& args) {
1595
1558
uvwasi_serdes_write_roflags_t (memory, ro_flags_ptr, ro_flags);
1596
1559
}
1597
1560
1598
- free (ri_data);
1599
1561
args.GetReturnValue ().Set (err);
1600
1562
}
1601
1563
@@ -1632,35 +1594,27 @@ void WASI::SockSend(const FunctionCallbackInfo<Value>& args) {
1632
1594
mem_size,
1633
1595
so_datalen_ptr,
1634
1596
UVWASI_SERDES_SIZE_size_t);
1635
- uvwasi_ciovec_t * si_data = UncheckedCalloc<uvwasi_ciovec_t >(si_data_len);
1636
-
1637
- if (si_data == nullptr ) {
1638
- args.GetReturnValue ().Set (UVWASI_ENOMEM);
1639
- return ;
1640
- }
1641
-
1597
+ std::vector<uvwasi_ciovec_t > si_data (si_data_len);
1642
1598
uvwasi_errno_t err = uvwasi_serdes_readv_ciovec_t (memory,
1643
1599
mem_size,
1644
1600
si_data_ptr,
1645
- si_data,
1601
+ si_data. data () ,
1646
1602
si_data_len);
1647
1603
if (err != UVWASI_ESUCCESS) {
1648
- free (si_data);
1649
1604
args.GetReturnValue ().Set (err);
1650
1605
return ;
1651
1606
}
1652
1607
1653
1608
uvwasi_size_t so_datalen;
1654
1609
err = uvwasi_sock_send (&wasi->uvw_ ,
1655
1610
sock,
1656
- si_data,
1611
+ si_data. data () ,
1657
1612
si_data_len,
1658
1613
si_flags,
1659
1614
&so_datalen);
1660
1615
if (err == UVWASI_ESUCCESS)
1661
1616
uvwasi_serdes_write_size_t (memory, so_datalen_ptr, so_datalen);
1662
1617
1663
- free (si_data);
1664
1618
args.GetReturnValue ().Set (err);
1665
1619
}
1666
1620
0 commit comments