Skip to content

Commit

Permalink
fix leak
Browse files Browse the repository at this point in the history
  • Loading branch information
traines-source committed Sep 24, 2024
1 parent d1815ef commit 82ec423
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/abi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,11 @@ nigiri_route_t* nigiri_get_route(const nigiri_timetable_t* t, uint32_t idx) {
auto stops = t->tt->route_location_seq_[ridx];
auto route = new nigiri_route_t;
auto const n_stops = stops.size();
route->stops = new nigiri_route_stop_t[n_stops];
if (n_stops > 0) {
auto route_stops = new nigiri_route_stop_t[n_stops];
std::memcpy(route_stops, &stops.front(),
std::memcpy(route->stops, &stops.front(),
sizeof(nigiri_route_stop_t) * n_stops);
route->stops = route_stops;
}

route->n_stops = static_cast<uint16_t>(n_stops);
route->clasz =
static_cast<uint16_t>(t->tt->route_section_clasz_[ridx].front());
Expand Down Expand Up @@ -213,8 +211,8 @@ nigiri_location_t* nigiri_get_location_with_footpaths(
? t->tt->locations_.footpaths_in_[0][lidx]
: t->tt->locations_.footpaths_out_[0][lidx];
auto const n_footpaths = footpaths.size();
location->footpaths = new nigiri_footpath_t[n_footpaths];
if (n_footpaths > 0) {
location->footpaths = new nigiri_footpath_t[n_footpaths];
std::memcpy(location->footpaths, &footpaths.front(),
sizeof(nigiri_footpath_t) * n_footpaths);
}
Expand All @@ -232,6 +230,7 @@ nigiri_location_t* nigiri_get_location(const nigiri_timetable_t* t,
}

void nigiri_destroy_location(const nigiri_location_t* location) {
delete[] location->footpaths;
delete location;
}

Expand Down

0 comments on commit 82ec423

Please sign in to comment.