[waffle] [PATCH 03/33] cgl: avoid leaking the PixelFormat

Emil Velikov emil.l.velikov at gmail.com
Mon Jul 7 10:28:10 PDT 2014


According to apple developer page, starting with OS X v10.5 the
pixelformat is reference counted. The object is created at
CGLChoosePixelFormat and should be unrefeferenced via
CGLReleasePixelFormat/CGLDestroyPixelFormat.

The latter two are identical accoring to the documentation.

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/waffle/cgl/cgl_config.m | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/waffle/cgl/cgl_config.m b/src/waffle/cgl/cgl_config.m
index 7a74438..5252e12 100644
--- a/src/waffle/cgl/cgl_config.m
+++ b/src/waffle/cgl/cgl_config.m
@@ -50,6 +50,9 @@ cgl_config_destroy(struct wcore_config *wc_self)
     if (wc_self == NULL)
         return ok;
 
+    if (self->pixel_format)
+        CGLReleasePixelFormat(self->pixel_format);
+
     ok &= wcore_config_teardown(wc_self);
     free(cgl_config(wc_self));
     return ok;
@@ -248,6 +251,7 @@ cgl_config_choose(struct wcore_platform *wc_plat,
     if (!ok)
         goto error;
 
+    // Starting with OS X v10.5, pixel format objects are reference counted.
     error = CGLChoosePixelFormat(pixel_attrs, &self->pixel_format, &ignore);
     if (error) {
         cgl_error_failed_func("CGLChoosePixelFormat", error);
-- 
2.0.0



More information about the waffle mailing list