From 36a0fd36456a7ae909cc04e20781b489c4ddc37b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sun, 28 Aug 2011 12:37:30 +0100 Subject: [PATCH] Dont't leak blobs all the time. Only leak blobs that are bound, and only in glretrace. --- glretrace.py | 2 +- trace_model.cpp | 18 +++++++++++++++--- trace_model.hpp | 6 ++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/glretrace.py b/glretrace.py index b775609..6a5103e 100644 --- a/glretrace.py +++ b/glretrace.py @@ -302,7 +302,7 @@ class GlRetracer(Retracer): def extract_arg(self, function, arg, arg_type, lvalue, rvalue): if function.name in self.array_pointer_function_names and arg.name == 'pointer': - print ' %s = static_cast<%s>(%s.toPointer());' % (lvalue, arg_type, rvalue) + print ' %s = static_cast<%s>(%s.toPointer(true));' % (lvalue, arg_type, rvalue) return if function.name in self.draw_elements_function_names and arg.name == 'indices': diff --git a/trace_model.cpp b/trace_model.cpp index 79bb757..25dc4bb 100644 --- a/trace_model.cpp +++ b/trace_model.cpp @@ -56,9 +56,16 @@ Array::~Array() { } Blob::~Blob() { - // TODO: Don't leak blobs. Blobs are often bound and accessed during many - // calls, so we can't delete them here. - //delete [] buf; + // Blobs are often bound and referred during many calls, so we can't delete + // them here in that case. + // + // Once bound there is no way to know when they were unbound, which + // effectively means we have to leak them. A better solution would be to + // keep a list of bound pointers, and defer the destruction to when the + // trace in question has been fully processed. + if (!bound) { + delete [] buf; + } } @@ -122,6 +129,11 @@ void * Null ::toPointer(void) const { return NULL; } void * Blob ::toPointer(void) const { return buf; } void * Pointer::toPointer(void) const { return (void *)value; } +void * Value ::toPointer(bool bind) { assert(0); return NULL; } +void * Null ::toPointer(bool bind) { return NULL; } +void * Blob ::toPointer(bool bind) { if (bind) bound = true; return buf; } +void * Pointer::toPointer(bool bind) { return (void *)value; } + // pointer cast unsigned long long Value ::toUIntPtr(void) const { assert(0); return 0; } diff --git a/trace_model.hpp b/trace_model.hpp index 5c51bba..a284754 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -96,6 +96,7 @@ public: virtual double toDouble(void) const; virtual void *toPointer(void) const; + virtual void *toPointer(bool bind); virtual unsigned long long toUIntPtr(void) const; virtual const char *toString(void) const; @@ -114,6 +115,7 @@ public: virtual float toFloat(void) const; virtual double toDouble(void) const; void *toPointer(void) const; + void *toPointer(bool bind); unsigned long long toUIntPtr(void) const; const char *toString(void) const; void visit(Visitor &visitor); @@ -257,16 +259,19 @@ public: Blob(size_t _size) { size = _size; buf = new char[_size]; + bound = false; } ~Blob(); bool toBool(void) const; void *toPointer(void) const; + void *toPointer(bool bind); void visit(Visitor &visitor); size_t size; char *buf; + bool bound; }; @@ -277,6 +282,7 @@ public: bool toBool(void) const; void *toPointer(void) const; + void *toPointer(bool bind); unsigned long long toUIntPtr(void) const; void visit(Visitor &visitor); }; -- 2.7.4