diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 129: Free memory alloacated by scenes and benchmarks on program exit.

Message ID 20110907094415.13575.66028.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org Sept. 7, 2011, 9:44 a.m. UTC
------------------------------------------------------------
revno: 129
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: trunk
timestamp: Wed 2011-09-07 12:40:57 +0300
message:
  Free memory alloacated by scenes and benchmarks on program exit.
  
  Although this is not really necessary, it removes some annoying valgrind leak
  reports and therefore makes it easier to discover *real* memory leaks.
modified:
  src/main.cpp
  src/util.h


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/main.cpp'
--- src/main.cpp	2011-08-18 15:03:40 +0000
+++ src/main.cpp	2011-09-07 09:40:57 +0000
@@ -26,6 +26,7 @@ 
 #include "benchmark.h"
 #include "options.h"
 #include "log.h"
+#include "util.h"
 
 #include <iostream>
 
@@ -82,6 +83,28 @@ 
     }
 }
 
+void
+add_and_register_scenes(vector<Scene*>& scenes, Canvas& canvas)
+{
+    scenes.push_back(new SceneDefaultOptions(canvas));
+    scenes.push_back(new SceneBuild(canvas));
+    scenes.push_back(new SceneTexture(canvas));
+    scenes.push_back(new SceneShading(canvas));
+    scenes.push_back(new SceneConditionals(canvas));
+    scenes.push_back(new SceneFunction(canvas));
+    scenes.push_back(new SceneLoop(canvas));
+    scenes.push_back(new SceneBump(canvas));
+    scenes.push_back(new SceneEffect2D(canvas));
+    scenes.push_back(new ScenePulsar(canvas));
+
+    for (vector<Scene*>::const_iterator iter = scenes.begin();
+         iter != scenes.end();
+         iter++)
+    {
+        Benchmark::register_scene(**iter);
+    }
+}
+
 static void
 list_scenes()
 {
@@ -220,17 +243,10 @@ 
     CanvasX11EGL canvas(Options::size.first, Options::size.second);
 #endif
 
-    // Register the scenes, so they can be looked-up by name
-    Benchmark::register_scene(*new SceneDefaultOptions(canvas));
-    Benchmark::register_scene(*new SceneBuild(canvas));
-    Benchmark::register_scene(*new SceneTexture(canvas));
-    Benchmark::register_scene(*new SceneShading(canvas));
-    Benchmark::register_scene(*new SceneConditionals(canvas));
-    Benchmark::register_scene(*new SceneFunction(canvas));
-    Benchmark::register_scene(*new SceneLoop(canvas));
-    Benchmark::register_scene(*new SceneBump(canvas));
-    Benchmark::register_scene(*new SceneEffect2D(canvas));
-    Benchmark::register_scene(*new ScenePulsar(canvas));
+    vector<Scene*> scenes;
+
+    // Register the scenes, so they can be looked up by name
+    add_and_register_scenes(scenes, canvas);
 
     if (Options::list_scenes) {
         list_scenes();
@@ -263,5 +279,8 @@ 
     else
         do_benchmark(canvas, benchmarks);
 
+    Util::dispose_pointer_vector(benchmarks);
+    Util::dispose_pointer_vector(scenes);
+
     return 0;
 }

=== modified file 'src/util.h'
--- src/util.h	2011-08-10 17:58:47 +0000
+++ src/util.h	2011-09-07 09:40:57 +0000
@@ -35,6 +35,18 @@ 
 struct Util {
     static void split(const std::string &s, char delim, std::vector<std::string> &elems);
     static std::istream *get_resource(const std::string &path);
+    template <class T> static void dispose_pointer_vector(std::vector<T*> &vec)
+    {
+        for (typename std::vector<T*>::const_iterator iter = vec.begin();
+             iter != vec.end();
+             iter++)
+        {
+            delete *iter;
+        }
+
+        vec.clear();
+    }
+
 #ifdef ANDROID
     static void android_set_asset_manager(AAssetManager *asset_manager);
 private: