From 19b8902db355fff22f9ec466f93600440bed9cdb Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Thu, 28 Nov 2019 14:46:30 +0100 Subject: [PATCH] Fix a resource leak This bug was detected via Coverity static analysis: Variable tempfile going out of scope leaks the storage it points to. The leak happens when invalid keyboard layout file is being loaded: $ touch xx.kl $ dosbox . C:\>keyb xx --- src/dos/dos_keyboard_layout.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dos/dos_keyboard_layout.cpp b/src/dos/dos_keyboard_layout.cpp index f600fc63..579a048e 100644 --- a/src/dos/dos_keyboard_layout.cpp +++ b/src/dos/dos_keyboard_layout.cpp @@ -317,6 +317,7 @@ Bitu keyboard_layout::read_keyboard_file(const char* keyboard_file_name, Bit32s Bit32u dr=(Bit32u)fread(read_buf, sizeof(Bit8u), 4, tempfile); if ((dr<4) || (read_buf[0]!=0x4b) || (read_buf[1]!=0x4c) || (read_buf[2]!=0x46)) { LOG(LOG_BIOS,LOG_ERROR)("Invalid keyboard layout file %s",keyboard_file_name); + fclose(tempfile); return KEYB_INVALIDFILE; } @@ -670,6 +671,7 @@ Bit16u keyboard_layout::extract_codepage(const char* keyboard_file_name) { Bit32u dr=(Bit32u)fread(read_buf, sizeof(Bit8u), 4, tempfile); if ((dr<4) || (read_buf[0]!=0x4b) || (read_buf[1]!=0x4c) || (read_buf[2]!=0x46)) { LOG(LOG_BIOS,LOG_ERROR)("Invalid keyboard layout file %s",keyboard_file_name); + fclose(tempfile); return 437; }