From 7c834907b18980b4a279741522e7ecc4a70434dd Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sat, 20 Jul 2024 06:48:06 -0600 Subject: [PATCH] fix memory leaks writing garmin routes. (#1299) --- garmin.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/garmin.cc b/garmin.cc index cea5e6c4d..29036fd3e 100644 --- a/garmin.cc +++ b/garmin.cc @@ -981,7 +981,7 @@ GarminFormat::route_waypt_pr(const Waypoint* wpt) void GarminFormat::route_write() { - int n = 2 * route_waypt_count(); /* Doubled for the islink crap. */ + const int n = 2 * route_waypt_count(); /* Doubled for the islink crap. */ tx_routelist = (GPS_SWay**) xcalloc(n,sizeof(GPS_PWay)); cur_tx_routelist_entry = tx_routelist; @@ -998,6 +998,12 @@ GarminFormat::route_write() }; route_disp_all(route_hdr_pr_lambda, nullptr, route_waypt_pr_lambda); GPS_Command_Send_Route(portname, tx_routelist, n); + + for (int i = 0; i < n; i++) { + GPS_Way_Del(&tx_routelist[i]); + } + + xfree(tx_routelist); } void