Permalink
Browse files

Fixed slight memory leak in sf::Font

  • Loading branch information...
dermoumi authored and eXpl0it3r committed Apr 7, 2017
1 parent 700fc7d commit c43b5991afe815ef92a812d67f8af12b0143adfd
Showing with 10 additions and 3 deletions.
  1. +10 −3 src/SFML/Graphics/Font.cpp
@@ -151,19 +151,21 @@ bool Font::loadFromFile(const std::string& filename)
if (FT_Stroker_New(static_cast<FT_Library>(m_library), &stroker) != 0)
{
err() << "Failed to load font \"" << filename << "\" (failed to create the stroker)" << std::endl;
FT_Done_Face(face);
return false;
}
m_stroker = stroker;
// Select the unicode character map
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_Stroker_Done(stroker);
FT_Done_Face(face);
return false;
}
// Store the loaded font in our ugly void* :)
m_stroker = stroker;
m_face = face;
// Store the font information
@@ -214,19 +216,21 @@ bool Font::loadFromMemory(const void* data, std::size_t sizeInBytes)
if (FT_Stroker_New(static_cast<FT_Library>(m_library), &stroker) != 0)
{
err() << "Failed to load font from memory (failed to create the stroker)" << std::endl;
FT_Done_Face(face);
return false;
}
m_stroker = stroker;
// Select the Unicode character map
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_Stroker_Done(stroker);
FT_Done_Face(face);
return false;
}
// Store the loaded font in our ugly void* :)
m_stroker = stroker;
m_face = face;
// Store the font information
@@ -287,20 +291,23 @@ bool Font::loadFromStream(InputStream& stream)
if (FT_Stroker_New(static_cast<FT_Library>(m_library), &stroker) != 0)
{
err() << "Failed to load font from stream (failed to create the stroker)" << std::endl;
FT_Done_Face(face);
delete rec;
return false;
}
m_stroker = stroker;
// 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);
FT_Stroker_Done(stroker);
delete rec;
return false;
}
// Store the loaded font in our ugly void* :)
m_stroker = stroker;
m_face = face;
m_streamRec = rec;

0 comments on commit c43b599

Please sign in to comment.