1
0
Fork 0

Miscellaneous tweaks and Bugfixes. Mostly memory leaks ported from the plib

version
* Delete ai list objects in ~ATC/AIMgr.cxx:AIMgr::~AIMgr()
* Delete colors in GUI/new_gui.cxx: NewGui::~NewGui.cxx
* Delete memory allocated to the class member "route" in
  Instrumentation/gps.cxx
* Delete all globals (except a few "unsafe" ones that still cause segfaults
  and need further examination.
* Use an SGShared pointer for navaid memory allocation, so that pointers to
  individual navaid objects can be included safely in multiple navaid lists
This commit is contained in:
durk 2007-10-20 08:36:21 +00:00
parent 6d3ff7b125
commit f5e9e1898f
7 changed files with 94 additions and 17 deletions

View file

@ -59,6 +59,9 @@ FGAIMgr::FGAIMgr() {
}
FGAIMgr::~FGAIMgr() {
for (ai_list_itr = ai_list.begin(); ai_list_itr != ai_list.end(); ai_list_itr++) {
delete (*ai_list_itr);
}
}
void FGAIMgr::init() {

View file

@ -35,6 +35,8 @@ NewGUI::~NewGUI ()
{
delete _menubar;
_dialog_props.clear();
for (_itt_t it = _colors.begin(); it != _colors.end(); ++it)
delete it->second;
}
void

View file

@ -43,17 +43,20 @@ GPS::GPS ( SGPropertyNode *node)
_distance_m(0),
_course_deg(0),
_name(node->getStringValue("name", "gps")),
_num(node->getIntValue("number", 0))
_num(node->getIntValue("number", 0)),
route(0)
{
}
GPS::~GPS ()
{
delete route;
}
void
GPS::init ()
{
delete route; // in case init is called twice
route = new SGRoute;
route->clear();

View file

@ -24,11 +24,28 @@
# include <config.h>
#endif
#include <simgear/scene/model/modellib.hxx>
#include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/structure/commands.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/timing/sg_time.hxx>
#include <simgear/ephemeris/ephemeris.hxx>
#include <simgear/magvar/magvar.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <Aircraft/controls.hxx>
#include <Airports/runways.hxx>
#include <ATC/AIMgr.hxx>
#include <ATC/ATCmgr.hxx>
#include <Autopilot/route_mgr.hxx>
#include <Cockpit/panel.hxx>
#include <GUI/new_gui.hxx>
#include <Model/acmodel.hxx>
#include <Model/modelmgr.hxx>
#include <MultiPlayer/multiplaymgr.hxx>
#include <Navaids/awynet.hxx>
#include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx>
#include "globals.hxx"
#include "renderer.hxx"
@ -97,15 +114,57 @@ FGGlobals::FGGlobals() :
// Destructor
FGGlobals::~FGGlobals()
{
delete soundmgr;
delete subsystem_mgr;
delete event_mgr;
delete initial_state;
delete props;
delete io;
delete fontcache;
delete renderer;
delete initial_waypoints;
// The AIModels manager performs a number of actions upon
// Shutdown that implicitly assume that other subsystems
// are still operational (Due to the dynamic allocation and
// deallocation of AIModel objects. To ensure we can safely
// shut down all subsystems, make sure we take down the
// AIModels system first.
subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("ai_model");
delete subsystem_mgr;
delete event_mgr;
delete time_params;
delete ephem;
delete mag;
delete matlib;
delete route_mgr;
delete current_panel;
delete soundmgr;
delete airports;
delete runways;
delete ATC_mgr;
delete AI_mgr;
delete controls;
delete viewmgr;
delete initial_state;
// //delete locale; Don't delete locale
// delete commands;
delete model_lib;
delete acmodel;
delete model_mgr;
delete channel_options_list;
delete initial_waypoints;
delete scenery;
//delete tile_mgr; // Don't delete tile manager yet, because loader thread problems
delete io;
delete fontcache;
delete navlist;
delete loclist;
delete gslist;
delete dmelist;
delete mkrlist;
delete tacanlist;
delete carrierlist;
delete channellist;
delete fixlist;
delete airwaynet;
delete multiplayer_mgr;
delete props;
}

View file

@ -54,13 +54,18 @@ FGNavList::FGNavList( void )
FGNavList::~FGNavList( void )
{
navaids_by_tile.erase( navaids_by_tile.begin(), navaids_by_tile.end() );
nav_list_type navlist = navaids.begin()->second;
navaids.erase( navaids.begin(), navaids.end() );
}
// load the navaids and build the map
bool FGNavList::init()
{
// FIXME: leaves all the individual navaid entries leaked
// No need to delete the original navaid structures
// since we're using an SGSharedPointer
nav_list_type navlist = navaids.begin()->second;
navaids.erase( navaids.begin(), navaids.end() );
navaids_by_tile.erase( navaids_by_tile.begin(), navaids_by_tile.end() );
ident_navaids.erase( ident_navaids.begin(), ident_navaids.end() );
@ -80,7 +85,7 @@ static void real_add( nav_map_type &navmap, const int master_index,
// front end for add a marker beacon
static void tile_add( nav_map_type &navmap, FGNavRecord *n )
{
double diff;
double diff = 0;
double lon = n->get_lon();
double lat = n->get_lat();

View file

@ -27,6 +27,8 @@
#include <simgear/compiler.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/structure/SGReferenced.hxx>
#include <map>
#include <vector>
@ -42,8 +44,8 @@ SG_USING_STD(string);
// FGNavList ------------------------------------------------------------------
typedef vector < FGNavRecord* > nav_list_type;
typedef SGSharedPtr<FGNavRecord> nav_rec_ptr;
typedef vector < nav_rec_ptr > nav_list_type;
typedef nav_list_type::iterator nav_list_iterator;
typedef nav_list_type::const_iterator nav_list_const_iterator;
@ -114,8 +116,8 @@ public:
// FGTACANList ----------------------------------------------------------------
typedef vector < FGTACANRecord* > tacan_list_type;
typedef SGSharedPtr<FGTACANRecord> tacan_rec_ptr;
typedef vector < tacan_rec_ptr > tacan_list_type;
typedef map < int, tacan_list_type > tacan_map_type;
typedef map < string, tacan_list_type > tacan_ident_map_type;

View file

@ -32,6 +32,9 @@
#include <simgear/magvar/magvar.hxx>
#include <simgear/timing/sg_time.hxx>
#include <simgear/structure/ssgSharedPtr.hxx>
#include <simgear/structure/SGReferenced.hxx>
#ifdef SG_HAVE_STD_INCLUDES
# include <istream>
#elif defined( __BORLANDC__ ) || (__APPLE__)
@ -58,7 +61,7 @@ enum fg_nav_types {
FG_NAV_ANY
};
class FGNavRecord {
class FGNavRecord : public SGReferenced {
int type;
SGGeod pos; // location in geodetic coords (degrees)
@ -194,7 +197,7 @@ operator >> ( istream& in, FGNavRecord& n )
return in;
}
class FGTACANRecord {
class FGTACANRecord : public SGReferenced {
string channel;
int freq;