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)
|
||||
{
|
||||
uint i;
|
||||
StringID *name;
|
||||
|
||||
for(i=0; i!=TOTAL_NUM_ENGINES; i++)
|
||||
_engine_name_strings[i] = STR_SV_EMPTY;
|
||||
for (name = _engine_name_strings; name != endof(_engine_name_strings); name++)
|
||||
*name = STR_SV_EMPTY;
|
||||
|
||||
DeleteCustomEngineNames();
|
||||
LoadCustomEngineNames();
|
||||
|
@ -200,7 +200,7 @@ void StartupEngines(void)
|
|||
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
|
||||
|
@ -214,7 +214,7 @@ struct WagonOverride {
|
|||
static struct WagonOverrides {
|
||||
int overrides_count;
|
||||
struct WagonOverride *overrides;
|
||||
} _engine_wagon_overrides[256];
|
||||
} _engine_wagon_overrides[TOTAL_NUM_ENGINES];
|
||||
|
||||
void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group,
|
||||
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)
|
||||
// (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
|
||||
// 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)
|
||||
{
|
||||
|
@ -622,14 +622,22 @@ void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger)
|
|||
DoTriggerVehicle(veh, trigger, 0, true);
|
||||
}
|
||||
|
||||
|
||||
static char *_engine_custom_names[256];
|
||||
static char *_engine_custom_names[TOTAL_NUM_ENGINES];
|
||||
|
||||
void SetCustomEngineName(int engine, const char *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)
|
||||
{
|
||||
if (!_engine_custom_names[engine])
|
||||
|
|
1
engine.h
1
engine.h
|
@ -134,6 +134,7 @@ void LoadCustomEngineNames(void);
|
|||
void DeleteCustomEngineNames(void);
|
||||
|
||||
bool IsEngineBuildable(uint engine, byte type);
|
||||
void UnInitNewgrEngines(void);
|
||||
|
||||
enum {
|
||||
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)
|
||||
{
|
||||
SDL_Surface *newscreen;
|
||||
char *caption;
|
||||
char caption[50];
|
||||
|
||||
GetAvailableVideoMode(&w, &h);
|
||||
|
||||
|
@ -348,7 +348,7 @@ static bool CreateMainSurface(int w, int h)
|
|||
_sdl_screen = newscreen;
|
||||
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_ShowCursor(0);
|
||||
|
||||
|
|
|
@ -82,8 +82,7 @@ static void GlobalSortStationList(void)
|
|||
uint16 *i;
|
||||
|
||||
// reset #-of stations to 0 because ++ is used for value-assignment
|
||||
for (i = _num_station_sort; i != endof(_num_station_sort); i++)
|
||||
*i = 0;
|
||||
memset(_num_station_sort, 0, sizeof(_num_station_sort));
|
||||
|
||||
/* Create array for sorting */
|
||||
_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);
|
||||
}
|
||||
|
||||
static void UnInitializeGame(void)
|
||||
{
|
||||
UnInitWindowSystem();
|
||||
UnInitNewgrEngines();
|
||||
}
|
||||
|
||||
static void LoadIntroGame(void)
|
||||
{
|
||||
|
@ -459,7 +464,7 @@ static void LoadIntroGame(void)
|
|||
LoadStringWidthTable();
|
||||
|
||||
// Setup main window
|
||||
InitWindowSystem();
|
||||
ResetWindowSystem();
|
||||
SetupColorsAndInitialWindow();
|
||||
|
||||
// Generate a world.
|
||||
|
@ -699,6 +704,7 @@ int ttd_main(int argc, char* argv[])
|
|||
|
||||
/* Close all and any open filehandles */
|
||||
FioCloseAll();
|
||||
UnInitializeGame();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -725,7 +731,7 @@ static void MakeNewGame(void)
|
|||
GfxLoadSprites();
|
||||
|
||||
// Reinitialize windows
|
||||
InitWindowSystem();
|
||||
ResetWindowSystem();
|
||||
LoadStringWidthTable();
|
||||
|
||||
SetupColorsAndInitialWindow();
|
||||
|
@ -757,7 +763,7 @@ static void MakeNewEditorWorld(void)
|
|||
GfxLoadSprites();
|
||||
|
||||
// Re-init the windowing system
|
||||
InitWindowSystem();
|
||||
ResetWindowSystem();
|
||||
|
||||
// Create toolbars
|
||||
SetupColorsAndInitialWindow();
|
||||
|
@ -792,7 +798,7 @@ static void StartScenario(void)
|
|||
GfxLoadSprites();
|
||||
|
||||
// Reinitialize windows
|
||||
InitWindowSystem();
|
||||
ResetWindowSystem();
|
||||
LoadStringWidthTable();
|
||||
|
||||
SetupColorsAndInitialWindow();
|
||||
|
@ -1327,7 +1333,7 @@ bool AfterLoadGame(uint version)
|
|||
}
|
||||
|
||||
// Initialize windows
|
||||
InitWindowSystem();
|
||||
ResetWindowSystem();
|
||||
SetupColorsAndInitialWindow();
|
||||
|
||||
w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||
|
|
23
window.c
23
window.c
|
@ -360,12 +360,11 @@ void AssignWidgetToWindow(Window *w, const Widget *widget)
|
|||
index++;
|
||||
}
|
||||
|
||||
w->widget = malloc(sizeof(Widget) * index);
|
||||
w->widget = realloc(w->widget, sizeof(Widget) * index);
|
||||
memcpy(w->widget, widget, sizeof(Widget) * index);
|
||||
} else {
|
||||
} else
|
||||
w->widget = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Window *AllocateWindow(
|
||||
int x,
|
||||
|
@ -427,6 +426,7 @@ Window *AllocateWindow(
|
|||
w->vscroll.count = 0;
|
||||
w->hscroll.pos = 0;
|
||||
w->hscroll.count = 0;
|
||||
w->widget = NULL;
|
||||
AssignWidgetToWindow(w, widget);
|
||||
w->resize.width = width;
|
||||
w->resize.height = height;
|
||||
|
@ -672,6 +672,7 @@ Window *FindWindowFromPt(int x, int y)
|
|||
void InitWindowSystem(void)
|
||||
{
|
||||
IConsoleClose();
|
||||
|
||||
memset(&_windows, 0, sizeof(_windows));
|
||||
_last_window = _windows;
|
||||
memset(_viewports, 0, sizeof(_viewports));
|
||||
|
@ -679,6 +680,22 @@ void InitWindowSystem(void)
|
|||
_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)
|
||||
{
|
||||
Window *w;
|
||||
|
|
Loading…
Reference in New Issue