From fc7da5edd1b26cc486b1f4d4b7e6c749c6109cc4 Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Sat, 13 Feb 2021 17:57:37 +0000 Subject: [PATCH] Fixes leaking of a file handle in case of an error. Refs #5288 Reported By: PVS-Studio This was SVN commit r24903. --- source/lib/sysdep/os/unix/unix.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/lib/sysdep/os/unix/unix.cpp b/source/lib/sysdep/os/unix/unix.cpp index ee8cf3cc0c..501516ecd8 100644 --- a/source/lib/sysdep/os/unix/unix.cpp +++ b/source/lib/sysdep/os/unix/unix.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2019 Wildfire Games. +/* Copyright (c) 2021 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -330,7 +330,10 @@ Status sys_generate_random_bytes(u8* buf, size_t count) { size_t numread = fread(buf, 1, count, f); if (numread == 0) + { + fclose(f); WARN_RETURN(ERR::FAIL); + } buf += numread; count -= numread; }