Fixed memory leaks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
diff --git a/include/FTList.h b/include/FTList.h
index 23c3105..f942d57 100644
--- a/include/FTList.h
+++ b/include/FTList.h
@@ -31,12 +31,12 @@ class FTGL_EXPORT FTList
*/
~FTList()
{
- Node* temp = head;
+ Node* next;
- while( temp->next)
+ for (Node *walk = head;walk;walk = next)
{
- temp = head->next;
- delete head;
+ next = walk->next;
+ delete walk;
}
}
@@ -59,11 +59,12 @@ class FTGL_EXPORT FTList
{
head->next = node;
}
-
+
+ if (tail) tail->next = node;
tail = node;
++listSize;
}
-
+
/**
* Get the item at the front of the list
*/
diff --git a/src/FTOutlineGlyph.cpp b/src/FTOutlineGlyph.cpp
index d2d290f..c1fe64c 100644
--- a/src/FTOutlineGlyph.cpp
+++ b/src/FTOutlineGlyph.cpp
@@ -11,12 +11,11 @@ FTOutlineGlyph::FTOutlineGlyph( FT_Glyph glyph)
return;
}
- FTVectoriser* vectoriser = new FTVectoriser( glyph);
+ FTVectoriser vectoriser( glyph);
- size_t numContours = vectoriser->ContourCount();
- if ( ( numContours < 1) || ( vectoriser->PointCount() < 3))
+ size_t numContours = vectoriser.ContourCount();
+ if ( ( numContours < 1) || ( vectoriser.PointCount() < 3))
{
- delete vectoriser;
return;
}
@@ -24,7 +23,7 @@ FTOutlineGlyph::FTOutlineGlyph( FT_Glyph glyph)
glNewList( glList, GL_COMPILE);
for( unsigned int c = 0; c < numContours; ++c)
{
- const FTContour* contour = vectoriser->Contour(c);
+ const FTContour* contour = vectoriser.Contour(c);
glBegin( GL_LINE_LOOP);
for( unsigned int p = 0; p < contour->PointCount(); ++p)
@@ -35,7 +34,6 @@ FTOutlineGlyph::FTOutlineGlyph( FT_Glyph glyph)
}
glEndList();
- delete vectoriser;
// discard glyph image (bitmap or not)
FT_Done_Glyph( glyph); // Why does this have to be HERE
diff --git a/src/FTPolyGlyph.cpp b/src/FTPolyGlyph.cpp
index dded757..fbd7cb2 100644
--- a/src/FTPolyGlyph.cpp
+++ b/src/FTPolyGlyph.cpp
@@ -11,20 +11,19 @@ FTPolyGlyph::FTPolyGlyph( FT_Glyph glyph)
return;
}
- FTVectoriser* vectoriser = new FTVectoriser( glyph);
+ FTVectoriser vectoriser( glyph);
- if(( vectoriser->ContourCount() < 1) || ( vectoriser->PointCount() < 3))
+ if(( vectoriser.ContourCount() < 1) || ( vectoriser.PointCount() < 3))
{
- delete vectoriser;
return;
}
- vectoriser->MakeMesh( 1.0);
+ vectoriser.MakeMesh( 1.0);
glList = glGenLists( 1);
glNewList( glList, GL_COMPILE);
- const FTMesh* mesh = vectoriser->GetMesh();
+ const FTMesh* mesh = vectoriser.GetMesh();
for( unsigned int index = 0; index < mesh->TesselationCount(); ++index)
{
const FTTesselation* subMesh = mesh->Tesselation( index);
diff --git a/src/FTVectoriser.cpp b/src/FTVectoriser.cpp
index cca5c36..4829594 100644
--- a/src/FTVectoriser.cpp
+++ b/src/FTVectoriser.cpp
@@ -1,7 +1,6 @@
#include "FTVectoriser.h"
#include "FTGL.h"
-
#ifndef CALLBACK
#define CALLBACK
#endif