From beddf05ff6da0df583682f9e56ef088b5d13f4b7 Mon Sep 17 00:00:00 2001 From: Bill-Gray Date: Wed, 21 Feb 2024 11:51:21 -0500 Subject: [PATCH] Follow-up to preceding commit 0619a3acb6ec337e1968101855cc9da : the array of NORAD numbers should be freed at shutdown. With this, Valgrind confirms that all memory has been properly freed. --- sat_id.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sat_id.cpp b/sat_id.cpp index 8c9c9b6..3c0e208 100644 --- a/sat_id.cpp +++ b/sat_id.cpp @@ -1044,7 +1044,7 @@ static int add_tle_to_obs( object_t *objects, const size_t n_objects, const double max_revs_per_day) { char line0[100], line1[100], line2[100]; - FILE *tle_file = fopen( tle_file_name, "rb"); + FILE *tle_file; int rval = 0, n_tles_found = 0; bool check_updates = true; bool look_for_tles = true; @@ -1053,6 +1053,14 @@ static int add_tle_to_obs( object_t *objects, const size_t n_objects, static int *norad_ids = NULL; static size_t n_norad_ids = 0; + if( !tle_file_name) /* flag to free internal memory at shutdown */ + { + if( norad_ids) + free( norad_ids); + n_norad_ids = 0; + return( 0); + } + tle_file = fopen( tle_file_name, "rb"); if( !tle_file) { #ifdef ON_LINE_VERSION @@ -1759,6 +1767,7 @@ int main( const int argc, const char **argv) free( objects[i].matches); free( objects); get_station_code_data( NULL, NULL); + add_tle_to_obs( NULL, 0, NULL, 0., 0.); printf( "\n%.1f seconds elapsed\n", (double)clock( ) / (double)CLOCKS_PER_SEC); return( rval); } /* End of main() */