Mitigation of resource leaks due to time structures.

This commit is contained in:
OBattler
2016-07-11 06:32:42 +02:00
parent 7f5d02f08d
commit 289f3fe96a
2 changed files with 16 additions and 11 deletions

View File

@@ -185,18 +185,19 @@ static void time_internal(struct tm **time_var)
(*time_var)->tm_year = internal_clock.year - 1900; (*time_var)->tm_year = internal_clock.year - 1900;
} }
time_t cur_time;
struct tm* cur_time_tm;
/* Periodic RTC update function /* Periodic RTC update function
See also: nvr_onesec() in nvr.c See also: nvr_onesec() in nvr.c
*/ */
void time_get(char *nvrram) void time_get(char *nvrram)
{ {
time_t cur_time;
struct tm* cur_time_tm;
int dow, mon, year; int dow, mon, year;
if (enable_sync) if (enable_sync)
{ {
cur_time = time(NULL); time(&cur_time);
/* Mingw doesn't support localtime_r */ /* Mingw doesn't support localtime_r */
#if __MINGW32__ #if __MINGW32__

View File

@@ -458,36 +458,40 @@ void take_screenshot()
{ {
} }
#else #else
time_t now;
struct tm *info;
char screenshot_fn[1024];
void take_screenshot() void take_screenshot()
{ {
char fn[1024];
time_t now = time(0);
if ((vid_api < 0) || (vid_api > 1)) return; if ((vid_api < 0) || (vid_api > 1)) return;
time(&now);
info = localtime(&now);
memset(fn, 0, 1024); memset(fn, 0, 1024);
pclog("Video API is: %i\n", vid_api); pclog("Video API is: %i\n", vid_api);
if (vid_api == 1) if (vid_api == 1)
{ {
strftime(fn, 1024, "screenshots/%Y%m%d_%H%M%S.png", localtime(&now)); strftime(screenshot_fn, 1024, "screenshots\\%Y%m%d_%H%M%S.png", info);
if (video_fullscreen) if (video_fullscreen)
{ {
d3d_fs_take_screenshot(fn); d3d_fs_take_screenshot(screenshot_fn);
} }
else else
{ {
pclog("Direct 3D...\n"); pclog("Direct 3D...\n");
d3d_take_screenshot(fn); d3d_take_screenshot(screenshot_fn);
} }
} }
else if (vid_api == 0) else if (vid_api == 0)
{ {
strftime(fn, 1024, "screenshots/%Y%m%d_%H%M%S.bmp", localtime(&now)); strftime(fn, 1024, "screenshots\\%Y%m%d_%H%M%S.bmp", info);
if (video_fullscreen) if (video_fullscreen)
{ {
ddraw_fs_take_screenshot(fn); ddraw_fs_take_screenshot(screenshot_fn);
} }
else else
{ {
ddraw_take_screenshot(fn); ddraw_take_screenshot(screenshot_fn);
} }
} }
} }