Skip to content

Commit

Permalink
Fixed file-descriptor leak if ImBitmapFont::LoadFromFile() calls to s…
Browse files Browse the repository at this point in the history
…eek/tell fails.
  • Loading branch information
ocornut committed Sep 10, 2014
1 parent 1cf4b31 commit 3fd68c3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5190,13 +5190,22 @@ bool ImBitmapFont::LoadFromFile(const char* filename)
if ((f = fopen(filename, "rb")) == NULL)
return false;
if (fseek(f, 0, SEEK_END))
{
fclose(f);
return false;
}
const long f_size = ftell(f);
if (f_size == -1)
{
fclose(f);
return false;
}
DataSize = (size_t)f_size;
if (fseek(f, 0, SEEK_SET))
{
fclose(f);
return false;
}
if ((Data = (unsigned char*)IM_MALLOC(DataSize)) == NULL)
{
fclose(f);
Expand Down

0 comments on commit 3fd68c3

Please sign in to comment.