Enabled freeing of (most) allocated memory on program exit
The Valgrind tool can give a full accounting of what memory allocations have yet to be free()d when the program exits. It is easier to find actual memory leaks in the code if all non-leaked allocations are elided from that accounting, which is most easily accomplished by free()ing them. The "most" qualifier is there because some allocations are difficult/ impossible to free, as they are internal to libraries like OpenGL and Xft. The best we can hope for is to cover all allocations made by SolveSpace directly.
This commit is contained in:
parent
42a46e83fa
commit
16179f34cd
3
dsc.h
3
dsc.h
|
@ -362,6 +362,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear(void) {
|
void Clear(void) {
|
||||||
|
for(int i = 0; i < n; i++) {
|
||||||
|
elem[i].Clear();
|
||||||
|
}
|
||||||
elemsAllocated = n = 0;
|
elemsAllocated = n = 0;
|
||||||
if(elem) MemFree(elem);
|
if(elem) MemFree(elem);
|
||||||
elem = NULL;
|
elem = NULL;
|
||||||
|
|
|
@ -38,7 +38,7 @@ void Group::AssembleLoops(bool *allClosed,
|
||||||
// This is a zero-length edge.
|
// This is a zero-length edge.
|
||||||
*allNonZeroLen = false;
|
*allNonZeroLen = false;
|
||||||
polyError.errorPointAt = sb->ctrl[0];
|
polyError.errorPointAt = sb->ctrl[0];
|
||||||
return;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ void Group::AssembleLoops(bool *allClosed,
|
||||||
allClosed, &(polyError.notClosedAt),
|
allClosed, &(polyError.notClosedAt),
|
||||||
allCoplanar, &(polyError.errorPointAt),
|
allCoplanar, &(polyError.errorPointAt),
|
||||||
&bezierOpens);
|
&bezierOpens);
|
||||||
|
done:
|
||||||
sbl.Clear();
|
sbl.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
sketch.h
14
sketch.h
|
@ -80,6 +80,8 @@ public:
|
||||||
hEntity input;
|
hEntity input;
|
||||||
int copyNumber;
|
int copyNumber;
|
||||||
// (input, copyNumber) gets mapped to ((Request)xxx).entity(h.v)
|
// (input, copyNumber) gets mapped to ((Request)xxx).entity(h.v)
|
||||||
|
|
||||||
|
void Clear(void) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// A set of requests. Every request must have an associated group.
|
// A set of requests. Every request must have an associated group.
|
||||||
|
@ -289,6 +291,8 @@ public:
|
||||||
void Generate(EntityList *entity, ParamList *param);
|
void Generate(EntityList *entity, ParamList *param);
|
||||||
|
|
||||||
char *DescriptionString(void);
|
char *DescriptionString(void);
|
||||||
|
|
||||||
|
void Clear(void) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_POINTS_IN_ENTITY (12)
|
#define MAX_POINTS_IN_ENTITY (12)
|
||||||
|
@ -428,6 +432,8 @@ public:
|
||||||
|
|
||||||
void AddEq(IdList<Equation,hEquation> *l, Expr *expr, int index);
|
void AddEq(IdList<Equation,hEquation> *l, Expr *expr, int index);
|
||||||
void GenerateEquations(IdList<Equation,hEquation> *l);
|
void GenerateEquations(IdList<Equation,hEquation> *l);
|
||||||
|
|
||||||
|
void Clear(void) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Entity : public EntityBase {
|
class Entity : public EntityBase {
|
||||||
|
@ -514,6 +520,8 @@ public:
|
||||||
hParam substd;
|
hParam substd;
|
||||||
|
|
||||||
static const hParam NO_PARAM;
|
static const hParam NO_PARAM;
|
||||||
|
|
||||||
|
void Clear(void) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -601,6 +609,8 @@ public:
|
||||||
static Expr *PointPlaneDistance(ExprVector p, hEntity plane);
|
static Expr *PointPlaneDistance(ExprVector p, hEntity plane);
|
||||||
static Expr *VectorsParallel(int eq, ExprVector a, ExprVector b);
|
static Expr *VectorsParallel(int eq, ExprVector a, ExprVector b);
|
||||||
static ExprVector PointInThreeSpace(hEntity workplane, Expr *u, Expr *v);
|
static ExprVector PointInThreeSpace(hEntity workplane, Expr *u, Expr *v);
|
||||||
|
|
||||||
|
void Clear(void) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Constraint : public ConstraintBase {
|
class Constraint : public ConstraintBase {
|
||||||
|
@ -668,6 +678,8 @@ public:
|
||||||
hEquation h;
|
hEquation h;
|
||||||
|
|
||||||
Expr *e;
|
Expr *e;
|
||||||
|
|
||||||
|
void Clear(void) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -759,6 +771,8 @@ public:
|
||||||
static hStyle ForEntity(hEntity he);
|
static hStyle ForEntity(hEntity he);
|
||||||
|
|
||||||
char *DescriptionString(void);
|
char *DescriptionString(void);
|
||||||
|
|
||||||
|
void Clear(void) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -734,3 +734,20 @@ void SolveSpace::MenuHelp(int id) {
|
||||||
default: oops();
|
default: oops();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SolveSpace::Clear(void) {
|
||||||
|
sys.Clear();
|
||||||
|
for(int i = 0; i < MAX_UNDO; i++) {
|
||||||
|
if(i < undo.cnt) undo.d[i].Clear();
|
||||||
|
if(i < redo.cnt) redo.d[i].Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sketch::Clear(void) {
|
||||||
|
group.Clear();
|
||||||
|
constraint.Clear();
|
||||||
|
request.Clear();
|
||||||
|
style.Clear();
|
||||||
|
entity.Clear();
|
||||||
|
param.Clear();
|
||||||
|
}
|
||||||
|
|
14
solvespace.h
14
solvespace.h
|
@ -328,6 +328,8 @@ public:
|
||||||
};
|
};
|
||||||
int Solve(Group *g, int *dof, List<hConstraint> *bad,
|
int Solve(Group *g, int *dof, List<hConstraint> *bad,
|
||||||
bool andFindBad, bool andFindFree);
|
bool andFindBad, bool andFindFree);
|
||||||
|
|
||||||
|
void Clear(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
class TtfFont {
|
class TtfFont {
|
||||||
|
@ -577,6 +579,8 @@ public:
|
||||||
inline Request *GetRequest(hRequest h) { return request.FindById(h); }
|
inline Request *GetRequest(hRequest h) { return request.FindById(h); }
|
||||||
inline Group *GetGroup (hGroup h) { return group. FindById(h); }
|
inline Group *GetGroup (hGroup h) { return group. FindById(h); }
|
||||||
// Styles are handled a bit differently.
|
// Styles are handled a bit differently.
|
||||||
|
|
||||||
|
void Clear(void);
|
||||||
};
|
};
|
||||||
#undef ENTITY
|
#undef ENTITY
|
||||||
#undef CONSTRAINT
|
#undef CONSTRAINT
|
||||||
|
@ -594,6 +598,14 @@ public:
|
||||||
IdList<Param,hParam> param;
|
IdList<Param,hParam> param;
|
||||||
IdList<Style,hStyle> style;
|
IdList<Style,hStyle> style;
|
||||||
hGroup activeGroup;
|
hGroup activeGroup;
|
||||||
|
|
||||||
|
void Clear(void) {
|
||||||
|
group.Clear();
|
||||||
|
request.Clear();
|
||||||
|
constraint.Clear();
|
||||||
|
param.Clear();
|
||||||
|
style.Clear();
|
||||||
|
}
|
||||||
} UndoState;
|
} UndoState;
|
||||||
enum { MAX_UNDO = 16 };
|
enum { MAX_UNDO = 16 };
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -813,6 +825,8 @@ public:
|
||||||
void DoLater(void);
|
void DoLater(void);
|
||||||
|
|
||||||
static void MenuHelp(int id);
|
static void MenuHelp(int id);
|
||||||
|
|
||||||
|
void Clear(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SolveSpace SS;
|
extern SolveSpace SS;
|
||||||
|
|
|
@ -526,3 +526,9 @@ didnt_converge:
|
||||||
return System::DIDNT_CONVERGE;
|
return System::DIDNT_CONVERGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void System::Clear(void) {
|
||||||
|
entity.Clear();
|
||||||
|
param.Clear();
|
||||||
|
eq.Clear();
|
||||||
|
dragged.Clear();
|
||||||
|
}
|
||||||
|
|
|
@ -1206,5 +1206,10 @@ done:
|
||||||
// Write everything back to the registry
|
// Write everything back to the registry
|
||||||
FreezeWindowPos(TextWnd);
|
FreezeWindowPos(TextWnd);
|
||||||
FreezeWindowPos(GraphicsWnd);
|
FreezeWindowPos(GraphicsWnd);
|
||||||
|
|
||||||
|
// Free the memory we've used; anything that remains is a leak.
|
||||||
|
SK.Clear();
|
||||||
|
SS.Clear();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user