Skip to content

Commit

Permalink
Fixed slight memory leak in sf::Font
Browse files Browse the repository at this point in the history
  • Loading branch information
dermoumi authored and eXpl0it3r committed Apr 25, 2017
1 parent 700fc7d commit c43b599
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/SFML/Graphics/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit c43b599

Please sign in to comment.