From 41473d915bb7b183415d51a3a3cc0e0c133a7a9d Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 21 Nov 2024 12:47:06 +0000 Subject: [PATCH] Fix a memory leak in Windows f_open. The UCS-2 translation of the access-mode string ("r", "wb" etc) was not being freed, because the free call appeared after an unconditional return statement. Spotted by Coverity, although now I wonder why an ordinary compiler warning hadn't long since pointed this one out! --- windows/utils/filename.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/windows/utils/filename.c b/windows/utils/filename.c index 5c1a0d12..68c4c1cf 100644 --- a/windows/utils/filename.c +++ b/windows/utils/filename.c @@ -87,6 +87,7 @@ char filename_char_sanitise(char c) FILE *f_open(const Filename *fn, const char *mode, bool isprivate) { wchar_t *wmode = dup_mb_to_wc(DEFAULT_CODEPAGE, mode); - return _wfopen(fn->wpath, wmode); + FILE *fp = _wfopen(fn->wpath, wmode); sfree(wmode); + return fp; }