From c6bd09648cee5ed3a37635d378e1c6ec6eee5267 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Sat, 15 Jun 2024 14:41:39 +0200 Subject: [PATCH] examples: ensure the file is closed In case of an error during memory allocation for file data, the file was not closed. --- examples/Text.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/Text.cpp b/examples/Text.cpp index 75d191ca..cf132281 100644 --- a/examples/Text.cpp +++ b/examples/Text.cpp @@ -58,12 +58,12 @@ void tvgDrawCmds(tvg::Canvas* canvas) auto size = file.tellg(); file.seekg(0, std::ios::beg); auto data = (char*)malloc(size); - if (!data) return; - file.read(data, size); - file.close(); - if (tvg::Text::load("SentyCloud", data, size, "ttf", true) != tvg::Result::Success) { - cout << "Error while loading TTF from memory. Did you enable TTF Loader?" << endl; + if (data && file.read(data, size)) { + if (tvg::Text::load("SentyCloud", data, size, "ttf", true) != tvg::Result::Success) { + cout << "Error while loading TTF from memory. Did you enable TTF Loader?" << endl; + } } + file.close(); free(data); auto text = tvg::Text::gen();