second round of review fixes
This commit is contained in:
parent
1dbd81067a
commit
49d505831d
54
rust/rust.cc
54
rust/rust.cc
@ -101,11 +101,12 @@ extern "C" {
|
|||||||
auto size = size_t{};
|
auto size = size_t{};
|
||||||
for (auto _pip : ctx->getPips())
|
for (auto _pip : ctx->getPips())
|
||||||
size++;
|
size++;
|
||||||
auto *pip_vec = new std::vector<uint64_t>{};
|
*pips = new uint64_t[size];
|
||||||
pip_vec->reserve(size);
|
auto idx = 0;
|
||||||
for (auto pip : ctx->getPips())
|
for (auto pip : ctx->getPips()) {
|
||||||
pip_vec->push_back(wrap(pip));
|
*pips[idx] = wrap(pip);
|
||||||
*pips = pip_vec->data();
|
idx++;
|
||||||
|
}
|
||||||
// Yes, by never deleting pip_vec, we leak memory.
|
// Yes, by never deleting pip_vec, we leak memory.
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@ -114,12 +115,13 @@ extern "C" {
|
|||||||
auto size = size_t{};
|
auto size = size_t{};
|
||||||
for (auto _wire : ctx->getWires())
|
for (auto _wire : ctx->getWires())
|
||||||
size++;
|
size++;
|
||||||
auto *wire_vec = new std::vector<uint64_t>{};
|
*wires = new uint64_t[size];
|
||||||
wire_vec->reserve(size);
|
auto idx = 0;
|
||||||
for (auto wire : ctx->getWires())
|
for (auto wire : ctx->getWires()) {
|
||||||
wire_vec->push_back(wrap(wire));
|
*wires[idx] = wrap(wire);
|
||||||
*wires = wire_vec->data();
|
idx++;
|
||||||
// Yes, by never deleting wire_vec, we leak memory.
|
}
|
||||||
|
// Yes, by never deleting wires, we leak memory.
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,17 +138,15 @@ extern "C" {
|
|||||||
|
|
||||||
uint32_t npnr_context_nets_leak(const Context *ctx, int **names, NetInfo ***nets) {
|
uint32_t npnr_context_nets_leak(const Context *ctx, int **names, NetInfo ***nets) {
|
||||||
auto size = ctx->nets.size();
|
auto size = ctx->nets.size();
|
||||||
auto *name_vec = new std::vector<int>{};
|
*names = new int[size];
|
||||||
auto *nets_vec = new std::vector<NetInfo*>{};
|
*nets = new NetInfo*[size];
|
||||||
name_vec->reserve(size);
|
auto idx = 0;
|
||||||
nets_vec->reserve(size);
|
|
||||||
for (auto& item : ctx->nets) {
|
for (auto& item : ctx->nets) {
|
||||||
name_vec->push_back(item.first.hash());
|
*names[idx] = item.first.hash();
|
||||||
nets_vec->push_back(item.second.get());
|
*nets[idx] = item.second.get();
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
*names = name_vec->data();
|
// Yes, by never deleting `names` and `nets` we leak memory.
|
||||||
*nets = nets_vec->data();
|
|
||||||
// Yes, by never deleting `name_vec` and `nets_vec` we leak memory.
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,16 +175,14 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t npnr_netinfo_users_leak(NetInfo *net, PortRef ***users) {
|
uint32_t npnr_netinfo_users_leak(NetInfo *net, PortRef ***users) {
|
||||||
auto x = std::vector<PortRef*>{};
|
auto size = net->users.entries();
|
||||||
|
*users = new PortRef*[size];
|
||||||
|
auto idx = 0;
|
||||||
for (auto& item : net->users) {
|
for (auto& item : net->users) {
|
||||||
x.push_back(&item);
|
*users[idx] = &item;
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
x.shrink_to_fit();
|
// Yes, by not freeing `users`, we leak memory.
|
||||||
*users = x.data();
|
|
||||||
auto size = x.size();
|
|
||||||
// Yes, by memcpying over `x` we leak memory.
|
|
||||||
auto dummy = std::vector<PortRef*>{};
|
|
||||||
std::memcpy(&x, &dummy, sizeof(dummy));
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user