]> git.cworth.org Git - apitrace/commitdiff
Dont't leak blobs all the time.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 28 Aug 2011 11:37:30 +0000 (12:37 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 28 Aug 2011 11:37:30 +0000 (12:37 +0100)
Only leak blobs that are bound, and only in glretrace.

glretrace.py
trace_model.cpp
trace_model.hpp

index b775609aa0eb79ca6f4daf538ed258febfcc54f6..6a5103e0db2523894d8ff60f7632191af4cc3f19 100644 (file)
@@ -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':
index 79bb7575801b4842c2bb23be04deacc9986a5c9d..25dc4bb487138a2e38a33f277940c733bab5ce7e 100644 (file)
@@ -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; }
index 5c51bba7d06c345a541b8dca59cebe1291d546f6..a2847547421f8972666681d0784882192e2fb628 100644 (file)
@@ -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);
 };