mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
This commit is contained in:
parent
9bc68d209f
commit
9bd079d425
26
engine.c
26
engine.c
|
@ -73,10 +73,10 @@ void LoadCustomEngineNames(void)
|
||||||
|
|
||||||
static void SetupEngineNames(void)
|
static void SetupEngineNames(void)
|
||||||
{
|
{
|
||||||
uint i;
|
StringID *name;
|
||||||
|
|
||||||
for(i=0; i!=TOTAL_NUM_ENGINES; i++)
|
for (name = _engine_name_strings; name != endof(_engine_name_strings); name++)
|
||||||
_engine_name_strings[i] = STR_SV_EMPTY;
|
*name = STR_SV_EMPTY;
|
||||||
|
|
||||||
DeleteCustomEngineNames();
|
DeleteCustomEngineNames();
|
||||||
LoadCustomEngineNames();
|
LoadCustomEngineNames();
|
||||||
|
@ -200,7 +200,7 @@ void StartupEngines(void)
|
||||||
AdjustAvailAircraft();
|
AdjustAvailAircraft();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 _engine_refit_masks[256];
|
uint32 _engine_refit_masks[TOTAL_NUM_ENGINES];
|
||||||
|
|
||||||
|
|
||||||
// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky
|
// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky
|
||||||
|
@ -214,7 +214,7 @@ struct WagonOverride {
|
||||||
static struct WagonOverrides {
|
static struct WagonOverrides {
|
||||||
int overrides_count;
|
int overrides_count;
|
||||||
struct WagonOverride *overrides;
|
struct WagonOverride *overrides;
|
||||||
} _engine_wagon_overrides[256];
|
} _engine_wagon_overrides[TOTAL_NUM_ENGINES];
|
||||||
|
|
||||||
void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group,
|
void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group,
|
||||||
byte *train_id, int trains)
|
byte *train_id, int trains)
|
||||||
|
@ -260,12 +260,12 @@ static struct SpriteGroup *GetWagonOverrideSpriteSet(byte engine, byte overridin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
byte _engine_original_sprites[256];
|
byte _engine_original_sprites[TOTAL_NUM_ENGINES];
|
||||||
// 0 - 28 are cargos, 29 is default, 30 is the advert (purchase list)
|
// 0 - 28 are cargos, 29 is default, 30 is the advert (purchase list)
|
||||||
// (It isn't and shouldn't be like this in the GRF files since new cargo types
|
// (It isn't and shouldn't be like this in the GRF files since new cargo types
|
||||||
// may appear in future - however it's more convenient to store it like this in
|
// may appear in future - however it's more convenient to store it like this in
|
||||||
// memory. --pasky)
|
// memory. --pasky)
|
||||||
static struct SpriteGroup _engine_custom_sprites[256][NUM_CID];
|
static struct SpriteGroup _engine_custom_sprites[TOTAL_NUM_ENGINES][NUM_CID];
|
||||||
|
|
||||||
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group)
|
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group)
|
||||||
{
|
{
|
||||||
|
@ -622,14 +622,22 @@ void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger)
|
||||||
DoTriggerVehicle(veh, trigger, 0, true);
|
DoTriggerVehicle(veh, trigger, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *_engine_custom_names[TOTAL_NUM_ENGINES];
|
||||||
static char *_engine_custom_names[256];
|
|
||||||
|
|
||||||
void SetCustomEngineName(int engine, const char *name)
|
void SetCustomEngineName(int engine, const char *name)
|
||||||
{
|
{
|
||||||
_engine_custom_names[engine] = strdup(name);
|
_engine_custom_names[engine] = strdup(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnInitNewgrEngines(void)
|
||||||
|
{
|
||||||
|
char **i;
|
||||||
|
for (i = _engine_custom_names; i != endof(_engine_custom_names); i++) {
|
||||||
|
free(*i);
|
||||||
|
*i = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StringID GetCustomEngineName(int engine)
|
StringID GetCustomEngineName(int engine)
|
||||||
{
|
{
|
||||||
if (!_engine_custom_names[engine])
|
if (!_engine_custom_names[engine])
|
||||||
|
|
1
engine.h
1
engine.h
|
@ -134,6 +134,7 @@ void LoadCustomEngineNames(void);
|
||||||
void DeleteCustomEngineNames(void);
|
void DeleteCustomEngineNames(void);
|
||||||
|
|
||||||
bool IsEngineBuildable(uint engine, byte type);
|
bool IsEngineBuildable(uint engine, byte type);
|
||||||
|
void UnInitNewgrEngines(void);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NUM_NORMAL_RAIL_ENGINES = 54,
|
NUM_NORMAL_RAIL_ENGINES = 54,
|
||||||
|
|
4
sdl.c
4
sdl.c
|
@ -330,7 +330,7 @@ extern const char _openttd_revision[];
|
||||||
static bool CreateMainSurface(int w, int h)
|
static bool CreateMainSurface(int w, int h)
|
||||||
{
|
{
|
||||||
SDL_Surface *newscreen;
|
SDL_Surface *newscreen;
|
||||||
char *caption;
|
char caption[50];
|
||||||
|
|
||||||
GetAvailableVideoMode(&w, &h);
|
GetAvailableVideoMode(&w, &h);
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ static bool CreateMainSurface(int w, int h)
|
||||||
_sdl_screen = newscreen;
|
_sdl_screen = newscreen;
|
||||||
InitPalette();
|
InitPalette();
|
||||||
|
|
||||||
caption = str_fmt("OpenTTD %s", _openttd_revision);
|
snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision);
|
||||||
SDL_CALL SDL_WM_SetCaption(caption, caption);
|
SDL_CALL SDL_WM_SetCaption(caption, caption);
|
||||||
SDL_CALL SDL_ShowCursor(0);
|
SDL_CALL SDL_ShowCursor(0);
|
||||||
|
|
||||||
|
|
|
@ -82,8 +82,7 @@ static void GlobalSortStationList(void)
|
||||||
uint16 *i;
|
uint16 *i;
|
||||||
|
|
||||||
// reset #-of stations to 0 because ++ is used for value-assignment
|
// reset #-of stations to 0 because ++ is used for value-assignment
|
||||||
for (i = _num_station_sort; i != endof(_num_station_sort); i++)
|
memset(_num_station_sort, 0, sizeof(_num_station_sort));
|
||||||
*i = 0;
|
|
||||||
|
|
||||||
/* Create array for sorting */
|
/* Create array for sorting */
|
||||||
_station_sort = realloc(_station_sort, GetStationPoolSize() * sizeof(_station_sort[0]));
|
_station_sort = realloc(_station_sort, GetStationPoolSize() * sizeof(_station_sort[0]));
|
||||||
|
|
16
ttd.c
16
ttd.c
|
@ -447,6 +447,11 @@ static void UnInitializeDynamicVariables(void)
|
||||||
free(_industry_sort);
|
free(_industry_sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void UnInitializeGame(void)
|
||||||
|
{
|
||||||
|
UnInitWindowSystem();
|
||||||
|
UnInitNewgrEngines();
|
||||||
|
}
|
||||||
|
|
||||||
static void LoadIntroGame(void)
|
static void LoadIntroGame(void)
|
||||||
{
|
{
|
||||||
|
@ -459,7 +464,7 @@ static void LoadIntroGame(void)
|
||||||
LoadStringWidthTable();
|
LoadStringWidthTable();
|
||||||
|
|
||||||
// Setup main window
|
// Setup main window
|
||||||
InitWindowSystem();
|
ResetWindowSystem();
|
||||||
SetupColorsAndInitialWindow();
|
SetupColorsAndInitialWindow();
|
||||||
|
|
||||||
// Generate a world.
|
// Generate a world.
|
||||||
|
@ -699,6 +704,7 @@ int ttd_main(int argc, char* argv[])
|
||||||
|
|
||||||
/* Close all and any open filehandles */
|
/* Close all and any open filehandles */
|
||||||
FioCloseAll();
|
FioCloseAll();
|
||||||
|
UnInitializeGame();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -725,7 +731,7 @@ static void MakeNewGame(void)
|
||||||
GfxLoadSprites();
|
GfxLoadSprites();
|
||||||
|
|
||||||
// Reinitialize windows
|
// Reinitialize windows
|
||||||
InitWindowSystem();
|
ResetWindowSystem();
|
||||||
LoadStringWidthTable();
|
LoadStringWidthTable();
|
||||||
|
|
||||||
SetupColorsAndInitialWindow();
|
SetupColorsAndInitialWindow();
|
||||||
|
@ -757,7 +763,7 @@ static void MakeNewEditorWorld(void)
|
||||||
GfxLoadSprites();
|
GfxLoadSprites();
|
||||||
|
|
||||||
// Re-init the windowing system
|
// Re-init the windowing system
|
||||||
InitWindowSystem();
|
ResetWindowSystem();
|
||||||
|
|
||||||
// Create toolbars
|
// Create toolbars
|
||||||
SetupColorsAndInitialWindow();
|
SetupColorsAndInitialWindow();
|
||||||
|
@ -792,7 +798,7 @@ static void StartScenario(void)
|
||||||
GfxLoadSprites();
|
GfxLoadSprites();
|
||||||
|
|
||||||
// Reinitialize windows
|
// Reinitialize windows
|
||||||
InitWindowSystem();
|
ResetWindowSystem();
|
||||||
LoadStringWidthTable();
|
LoadStringWidthTable();
|
||||||
|
|
||||||
SetupColorsAndInitialWindow();
|
SetupColorsAndInitialWindow();
|
||||||
|
@ -1327,7 +1333,7 @@ bool AfterLoadGame(uint version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize windows
|
// Initialize windows
|
||||||
InitWindowSystem();
|
ResetWindowSystem();
|
||||||
SetupColorsAndInitialWindow();
|
SetupColorsAndInitialWindow();
|
||||||
|
|
||||||
w = FindWindowById(WC_MAIN_WINDOW, 0);
|
w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
|
|
23
window.c
23
window.c
|
@ -360,12 +360,11 @@ void AssignWidgetToWindow(Window *w, const Widget *widget)
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
w->widget = malloc(sizeof(Widget) * index);
|
w->widget = realloc(w->widget, sizeof(Widget) * index);
|
||||||
memcpy(w->widget, widget, sizeof(Widget) * index);
|
memcpy(w->widget, widget, sizeof(Widget) * index);
|
||||||
} else {
|
} else
|
||||||
w->widget = NULL;
|
w->widget = NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Window *AllocateWindow(
|
Window *AllocateWindow(
|
||||||
int x,
|
int x,
|
||||||
|
@ -427,6 +426,7 @@ Window *AllocateWindow(
|
||||||
w->vscroll.count = 0;
|
w->vscroll.count = 0;
|
||||||
w->hscroll.pos = 0;
|
w->hscroll.pos = 0;
|
||||||
w->hscroll.count = 0;
|
w->hscroll.count = 0;
|
||||||
|
w->widget = NULL;
|
||||||
AssignWidgetToWindow(w, widget);
|
AssignWidgetToWindow(w, widget);
|
||||||
w->resize.width = width;
|
w->resize.width = width;
|
||||||
w->resize.height = height;
|
w->resize.height = height;
|
||||||
|
@ -672,6 +672,7 @@ Window *FindWindowFromPt(int x, int y)
|
||||||
void InitWindowSystem(void)
|
void InitWindowSystem(void)
|
||||||
{
|
{
|
||||||
IConsoleClose();
|
IConsoleClose();
|
||||||
|
|
||||||
memset(&_windows, 0, sizeof(_windows));
|
memset(&_windows, 0, sizeof(_windows));
|
||||||
_last_window = _windows;
|
_last_window = _windows;
|
||||||
memset(_viewports, 0, sizeof(_viewports));
|
memset(_viewports, 0, sizeof(_viewports));
|
||||||
|
@ -679,6 +680,22 @@ void InitWindowSystem(void)
|
||||||
_no_scroll = 0;
|
_no_scroll = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnInitWindowSystem(void)
|
||||||
|
{
|
||||||
|
Window *w;
|
||||||
|
// delete all malloced widgets
|
||||||
|
for (w = _windows; w != _last_window; w++) {
|
||||||
|
free(w->widget);
|
||||||
|
w->widget = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetWindowSystem(void)
|
||||||
|
{
|
||||||
|
UnInitWindowSystem();
|
||||||
|
InitWindowSystem();
|
||||||
|
}
|
||||||
|
|
||||||
static void DecreaseWindowCounters(void)
|
static void DecreaseWindowCounters(void)
|
||||||
{
|
{
|
||||||
Window *w;
|
Window *w;
|
||||||
|
|
2
window.h
2
window.h
|
@ -563,6 +563,8 @@ Window *AllocateWindowAutoPlace2(
|
||||||
void DrawWindowViewport(Window *w);
|
void DrawWindowViewport(Window *w);
|
||||||
|
|
||||||
void InitWindowSystem(void);
|
void InitWindowSystem(void);
|
||||||
|
void UnInitWindowSystem(void);
|
||||||
|
void ResetWindowSystem(void);
|
||||||
int GetMenuItemIndex(Window *w, int x, int y);
|
int GetMenuItemIndex(Window *w, int x, int y);
|
||||||
void MouseLoop(void);
|
void MouseLoop(void);
|
||||||
void UpdateWindows(void);
|
void UpdateWindows(void);
|
||||||
|
|
Loading…
Reference in New Issue