mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
examples: ensure the file is closed
In case of an error during memory allocation for file data, the file was not closed.
This commit is contained in:
parent
393fc88570
commit
7ec67baf9a
1 changed files with 5 additions and 5 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue