Eliminate several memory leaks.
All leaks found with valgrind while running the test suite. This commit also clears the Cairo cache to improve SNR of Valgrind output.
This commit is contained in:
parent
a2a50927e9
commit
4f49a8a9d4
@ -637,6 +637,7 @@ void Group::DrawFilledPaths(Canvas *canvas) {
|
||||
SPolygon sp = {};
|
||||
sbls.MakePwlInto(&sp);
|
||||
canvas->DrawPolygon(sp, hcf);
|
||||
sp.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,6 +144,11 @@ bool Canvas::Fill::Equals(const Fill &other) const {
|
||||
pattern == other.pattern);
|
||||
}
|
||||
|
||||
void Canvas::Clear() {
|
||||
strokes.Clear();
|
||||
fills.Clear();
|
||||
}
|
||||
|
||||
Canvas::hStroke Canvas::GetStroke(const Stroke &stroke) {
|
||||
for(const Stroke &s : strokes) {
|
||||
if(s.Equals(stroke)) return s.h;
|
||||
|
@ -98,6 +98,7 @@ public:
|
||||
StipplePattern stipplePattern;
|
||||
double stippleScale;
|
||||
|
||||
void Clear() { *this = {}; }
|
||||
bool Equals(const Stroke &other) const;
|
||||
};
|
||||
|
||||
@ -114,13 +115,15 @@ public:
|
||||
RgbaColor color;
|
||||
FillPattern pattern;
|
||||
|
||||
void Clear() { *this = {}; }
|
||||
bool Equals(const Fill &other) const;
|
||||
};
|
||||
|
||||
IdList<Stroke, hStroke> strokes;
|
||||
IdList<Fill, hFill> fills;
|
||||
|
||||
Canvas() : strokes(), fills() {};
|
||||
Canvas() : strokes(), fills() {}
|
||||
virtual void Clear();
|
||||
|
||||
hStroke GetStroke(const Stroke &stroke);
|
||||
hFill GetFill(const Fill &fill);
|
||||
@ -226,7 +229,7 @@ public:
|
||||
BBox bbox;
|
||||
|
||||
SurfaceRenderer() : camera(), lighting(), chordTolerance(), mesh(), bbox() {}
|
||||
virtual void Clear();
|
||||
void Clear() override;
|
||||
|
||||
// Canvas interface.
|
||||
const Camera &GetCamera() const override { return camera; }
|
||||
|
@ -352,6 +352,8 @@ void SurfaceRenderer::OutputInPaintOrder() {
|
||||
if(tr.meta.color.IsEmpty()) continue;
|
||||
OutputTriangle(tr);
|
||||
}
|
||||
|
||||
mp.Clear();
|
||||
}
|
||||
|
||||
for(auto eit : edges) {
|
||||
@ -382,6 +384,8 @@ void SurfaceRenderer::OutputInPaintOrder() {
|
||||
}
|
||||
|
||||
void SurfaceRenderer::Clear() {
|
||||
Canvas::Clear();
|
||||
|
||||
for(auto &eit : edges) {
|
||||
SEdgeList &el = eit.second;
|
||||
el.l.Clear();
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR})
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CAIRO_INCLUDE_DIRS})
|
||||
|
||||
set(testsuite_SOURCES
|
||||
harness.cpp
|
||||
|
@ -5,6 +5,7 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "harness.h"
|
||||
#include <regex>
|
||||
#include <cairo.h>
|
||||
#if defined(WIN32)
|
||||
#include <windows.h>
|
||||
#else
|
||||
@ -310,11 +311,15 @@ int main(int argc, char **argv) {
|
||||
if(failTally > 0) {
|
||||
fprintf(stderr, "Failure! %u checks failed\n",
|
||||
(unsigned)failTally);
|
||||
return 1;
|
||||
} else {
|
||||
fprintf(stderr, "Success! %u test cases (%u skipped), %u checks, %.3fs\n",
|
||||
(unsigned)ranTally, (unsigned)skippedTally,
|
||||
(unsigned)checkTally, testTime.count());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// At last, try to reset all caches we or our dependencies have, to make SNR
|
||||
// of memory checking tools like valgrind higher.
|
||||
cairo_debug_reset_static_data();
|
||||
|
||||
return (failTally > 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user