toddcarnes / novas

This is my copy of the US Naval Observatory's NOVAS-C software (https://aa.usno.navy.mil/software/novasc_intro) with a couple bug fixes applied. I've also enhanced it with the ability to open many more versions of the JPL ephemerides. Please give the USNO proper credit if you use this software.
5 stars 1 forks source link

ephem_close does not reset the EPHFILE pointer #2

Closed toddcarnes closed 4 years ago

toddcarnes commented 4 years ago

The check to see if an ephemeris file is already open will always be true if an ephemeris file was open at any point in the program, even if ephem_close was called. ephem_close does not reset the EPHFILE pointer to NULL. This bug will be addressed during the next overhaul of the ephemeris-access software.

Memory errors occur when a call to ephem_close occurs between two calls to ephem_open. The second time ephem_open is called, if (EPHFILE) is TRUE because EPHFILE is still the address that was assigned the first time.

Two calls to ephem_open without an intervening call to ephem_close will work because the EPHFILE still is open when if (EPHFILE) checks during the second ephem_open call.

Users who open multiple ephemeris files within a particular program may wish to edit the ephem_close function as follows:

if (EPHFILE) 
{ 
  error = (short int) fclose (EPHFILE); 
  EPHFILE = NULL; // new line, reset pointer 
  free (BUFFER); 
} 
return error;