Skip to content

Commit

Permalink
Merge pull request #509 from ophui-/master
Browse files Browse the repository at this point in the history
Fixed potential memory leak in sf::Font
  • Loading branch information
Bromeon committed Feb 15, 2014
2 parents 09860f7 + b5e7e43 commit 5266133
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/SFML/Graphics/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ bool Font::loadFromFile(const std::string& filename)
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
{
err() << "Failed to load font \"" << filename << "\" (failed to set the Unicode character set)" << std::endl;
FT_Done_Face(face);
return false;
}

Expand Down Expand Up @@ -172,6 +173,7 @@ bool Font::loadFromMemory(const void* data, std::size_t sizeInBytes)
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
{
err() << "Failed to load font from memory (failed to set the Unicode character set)" << std::endl;
FT_Done_Face(face);
return false;
}

Expand Down Expand Up @@ -227,13 +229,16 @@ bool Font::loadFromStream(InputStream& stream)
if (FT_Open_Face(static_cast<FT_Library>(m_library), &args, 0, &face) != 0)
{
err() << "Failed to load font from stream (failed to create the font face)" << std::endl;
delete rec;
return false;
}

// Select the unicode character map
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
{
err() << "Failed to load font from stream (failed to set the Unicode character set)" << std::endl;
FT_Done_Face(face);
delete rec;
return false;
}

Expand Down

0 comments on commit 5266133

Please sign in to comment.