Browse Source

Fix undefined behavior in Stream due to virtual call during destruction

Michael Ragazzon 3 years ago
parent
commit
5e5e02f4be

+ 1 - 1
Include/RmlUi/Core/StreamMemory.h

@@ -39,7 +39,7 @@ namespace Rml {
 	@author Lloyd Weehuizen
 	@author Lloyd Weehuizen
  */
  */
 
 
-class RMLUICORE_API StreamMemory : public Stream
+class RMLUICORE_API StreamMemory final : public Stream
 {
 {
 public:
 public:
 	/// Empty memory stream with default size buffer
 	/// Empty memory stream with default size buffer

+ 1 - 1
Source/Core/Stream.cpp

@@ -41,7 +41,7 @@ Stream::Stream()
 
 
 Stream::~Stream()
 Stream::~Stream()
 {
 {
-	Close();
+	Stream::Close();
 }
 }
 
 
 void Stream::Close()
 void Stream::Close()

+ 2 - 1
Source/Core/StreamFile.cpp

@@ -42,7 +42,7 @@ StreamFile::StreamFile()
 StreamFile::~StreamFile()
 StreamFile::~StreamFile()
 {
 {
 	if (file_handle)
 	if (file_handle)
-		Close();
+		StreamFile::Close();
 }
 }
 
 
 /// Attempts to open the stream pointing at a given URL.
 /// Attempts to open the stream pointing at a given URL.
@@ -78,6 +78,7 @@ void StreamFile::Close()
 	}
 	}
 
 
 	length = 0;
 	length = 0;
+	Stream::Close();
 }
 }
 
 
 /// Returns the size of this stream (in bytes).
 /// Returns the size of this stream (in bytes).

+ 1 - 1
Source/Core/StreamFile.h

@@ -38,7 +38,7 @@ namespace Rml {
 	@author Peter Curry
 	@author Peter Curry
  */
  */
 
 
-class StreamFile : public Stream
+class StreamFile final : public Stream
 {
 {
 public:
 public:
 	StreamFile();
 	StreamFile();