kmscube: fix resource leaks & freeing
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Tue, 19 Apr 2016 18:40:21 +0000 (21:40 +0300)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Tue, 19 Apr 2016 18:40:21 +0000 (21:40 +0300)
kmscube/cube-x11.cpp
kmscube/cube.cpp
kmscube/cube.h

index 648384d484cb5831a55c0461e0d3af999b028a53..82ef414b46f400a4f782fe7192c2d7ff97e0b6cb 100644 (file)
@@ -11,9 +11,9 @@ using namespace std;
 
 void main_x11()
 {
-       Display* display = XOpenDisplay(NULL);
+       Display* dpy = XOpenDisplay(NULL);
 
-       xcb_connection_t *c = XGetXCBConnection(display);
+       xcb_connection_t *c = XGetXCBConnection(dpy);
 
        /* Get the first screen */
        const xcb_setup_t      *setup  = xcb_get_setup (c);
@@ -67,24 +67,35 @@ void main_x11()
        xcb_map_window (c, window);
        xcb_flush (c);
 
-       EglState egl(display);
-       EglSurface surface(egl, (void*)(uintptr_t)window);
-       GlScene scene;
+       {
+               EglState egl(dpy);
+               EglSurface surface(egl, (void*)(uintptr_t)window);
+               GlScene scene;
 
-       scene.set_viewport(width, height);
+               scene.set_viewport(width, height);
 
-       int framenum = 0;
-
-       surface.make_current();
-       surface.swap_buffers();
-
-       xcb_generic_event_t *event;
-       while ( (event = xcb_poll_for_event (c)) ) {
+               unsigned framenum = 0;
 
                surface.make_current();
-               scene.draw(framenum++);
                surface.swap_buffers();
+
+               xcb_generic_event_t *event;
+               while ( (event = xcb_poll_for_event (c)) ) {
+
+                       free(event);
+
+                       if (s_num_frames && framenum >= s_num_frames)
+                               break;
+
+                       surface.make_current();
+                       scene.draw(framenum++);
+                       surface.swap_buffers();
+               }
        }
 
-       xcb_disconnect (c);
+       xcb_flush(c);
+       xcb_unmap_window(c, window);
+       xcb_destroy_window(c, window);
+
+       XCloseDisplay(dpy);
 }
index eb2f6134676a5074b0be9138e7540c1add2dcf83..42e05be410023c88cf9eb061ac4e2c80564418d2 100644 (file)
@@ -33,6 +33,7 @@ using namespace std;
 
 bool s_verbose;
 bool s_fullscreen;
+unsigned s_num_frames;
 
 int main(int argc, char *argv[])
 {
@@ -47,6 +48,11 @@ int main(int argc, char *argv[])
                {
                        s_fullscreen = true;
                }),
+               Option("n|numframes=",
+               [&](string s)
+               {
+                       s_num_frames = stoi(s);
+               }),
        };
 
        optionset.parse(argc, argv);
index 9a2acb7bdbecb0f8b4ef04d18540fb4752c7f90f..6368162930c594bc7fcd94d87c025c1892f4d6c3 100644 (file)
@@ -2,6 +2,7 @@
 
 extern bool s_verbose;
 extern bool s_fullscreen;
+extern unsigned s_num_frames;
 
 void main_null();
 void main_gbm();