fix some calendar-related leaks and issues

This commit is contained in:
Enno Rehling 2016-09-09 18:39:38 +02:00
parent 43aacd2355
commit cb381123ff
4 changed files with 27 additions and 11 deletions

View File

@ -38,22 +38,34 @@ void calendar_cleanup(void)
free(agename);
for (i = 0; i != seasons; ++i) {
free(seasonnames[i]);
if (seasonnames) {
for (i = 0; i != seasons; ++i) {
free(seasonnames[i]);
}
free(seasonnames);
seasonnames = 0;
}
free(seasonnames);
for (i = 0; i != months_per_year; ++i) {
free(monthnames[i]);
if (monthnames) {
for (i = 0; i != months_per_year; ++i) {
free(monthnames[i]);
}
free(storms);
storms = 0;
free(month_season);
month_season = 0;
free(monthnames);
monthnames = 0;
}
free(storms);
free(month_season);
free(monthnames);
for (i = 0; i != weeks_per_month; ++i) {
free(weeknames[i]);
free(weeknames2[i]);
if (weeknames)
free(weeknames[i]);
if (weeknames2)
free(weeknames2[i]);
}
free(weeknames);
weeknames = 0;
free(weeknames2);
weeknames2 = 0;
}

View File

@ -26,6 +26,7 @@
#include <util/message.h>
#include <races/races.h>
#include "calendar.h"
#include "chaos.h"
#include "creport.h"
#include "items.h"
@ -50,8 +51,8 @@ void game_done(void)
#ifdef REPORT_FORMAT_NR
report_cleanup();
#endif
calendar_cleanup();
#endif
calendar_cleanup();
free_functions();
free_config();
free_locales();

View File

@ -471,6 +471,8 @@ static int parse_calendar(xmlDocPtr doc)
}
xmlXPathFreeObject(xpathMonths);
xmlXPathFreeObject(xpathSeasons);
xmlFree(newyear);
newyear = NULL;
}
xmlXPathFreeObject(xpathCalendars);
xmlXPathFreeContext(xpath);

View File

@ -3,3 +3,4 @@ turn = get_turn()
eressea.free_game()
print("trying to read data from " .. turn)
eressea.read_game(turn .. ".dat")
eressea.free_game()