summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2016-04-19 21:40:21 +0300
committerTomi Valkeinen <tomi.valkeinen@ti.com>2016-04-19 21:40:21 +0300
commit5c559cf5ac9dc5361df4d76b39fe875107e4fcda (patch)
treeec3345b5589d6cd48f2f94ccfffbe79c45492103
parent85797e7acf5f4322dc715f71e473f026ebbbc837 (diff)
kmscube: fix resource leaks & freeing
-rw-r--r--kmscube/cube-x11.cpp41
-rw-r--r--kmscube/cube.cpp6
-rw-r--r--kmscube/cube.h1
3 files changed, 33 insertions, 15 deletions
diff --git a/kmscube/cube-x11.cpp b/kmscube/cube-x11.cpp
index 648384d..82ef414 100644
--- a/kmscube/cube-x11.cpp
+++ b/kmscube/cube-x11.cpp
@@ -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);
}
diff --git a/kmscube/cube.cpp b/kmscube/cube.cpp
index eb2f613..42e05be 100644
--- a/kmscube/cube.cpp
+++ b/kmscube/cube.cpp
@@ -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);
diff --git a/kmscube/cube.h b/kmscube/cube.h
index 9a2acb7..6368162 100644
--- a/kmscube/cube.h
+++ b/kmscube/cube.h
@@ -2,6 +2,7 @@
extern bool s_verbose;
extern bool s_fullscreen;
+extern unsigned s_num_frames;
void main_null();
void main_gbm();