[PATCH} fixing memory leak with cairo_win32_device (Bug 67171)

Submitted by Fred Beca on April 5, 2016, 10:22 a.m.

Details

Message ID CAKTSDKYwBV+N6fau5+4aVB9jbuZL9v59aoK=rW__qayrMboDQg@mail.gmail.com
State New
Headers show
Series "[PATCH} fixing memory leak with cairo_win32_device (Bug 67171)" ( rev: 1 ) in Cairo

Not browsing as part of any series.

Commit Message

Fred Beca April 5, 2016, 10:22 a.m.
Hi,

There have been a memory leak on win32 platform for a while because of the
static __cairo_win32_device object that is never released (see
https://bugs.freedesktop.org/show_bug.cgi?id=67171)

Please find attached a simple patch that fixes the problem by adding a
win32-specific cleanup call in the cairo_debug_reset_static_data function.
I hope it can be added to the official release to remove the leak.

Regards,

Fred

Patch hide | download patch | download mbox

Index: cairo-debug.c
===================================================================
--- cairo-debug.c (cairo-1.14.6)
+++ cairo-debug.c (working copy)
@@ -89,7 +89,9 @@ 
 #if CAIRO_HAS_DRM_SURFACE
     _cairo_drm_device_reset_static_data ();
 #endif
-
+#if CAIRO_HAS_WIN32_SURFACE
+    _cairo_win32_device_reset_static_data ();
+#endif
     _cairo_default_context_reset_static_data ();

 #if CAIRO_HAS_COGL_SURFACE
Index: cairoint.h
===================================================================
--- cairoint.h (cairo-1.14.6)
+++ cairoint.h (working copy)
@@ -442,6 +442,11 @@ 
 cairo_private void
 _cairo_win32_font_reset_static_data (void);

+#if CAIRO_HAS_WIN32_SURFACE
+cairo_private void
+_cairo_win32_device_reset_static_data (void);
+#endif
+
 #if CAIRO_HAS_COGL_SURFACE
 void
 _cairo_cogl_context_reset_static_data (void);
Index: win32/cairo-win32-device.c
===================================================================
--- win32/cairo-win32-device.c (cairo-1.14.6)
+++ win32/cairo-win32-device.c (working copy)
@@ -187,3 +187,12 @@ 

     return flags;
 }
+
+void _cairo_win32_device_reset_static_data (void)
+{
+     if (__cairo_win32_device != NULL) {
+ cairo_device_t *device = __cairo_win32_device;
+ __cairo_win32_device = NULL;
+ cairo_device_destroy (device);
+    }
+}

Comments

On 05/04/16 19:52, Fred Beca wrote:
> Hi,
> 
> There have been a memory leak on win32 platform for a while because of
> the static __cairo_win32_device object that is never released
> (see https://bugs.freedesktop.org/show_bug.cgi?id=67171)
> 
> Please find attached a simple patch that fixes the problem by adding a
> win32-specific cleanup call in the cairo_debug_reset_static_data
> function. I hope it can be added to the official release to remove the leak.

If you could add the patch to bug 67171 and I will test and commit it
next time I am working on the windows backend.

> 
> Regards,
> 
> Fred
> 
> Index: cairo-debug.c
> ===================================================================
> --- cairo-debug.c(cairo-1.14.6)
> +++ cairo-debug.c(working copy)
> @@ -89,7 +89,9 @@
>  #if CAIRO_HAS_DRM_SURFACE
>      _cairo_drm_device_reset_static_data ();
>  #endif
> -
> +#if CAIRO_HAS_WIN32_SURFACE
> +    _cairo_win32_device_reset_static_data ();
> +#endif
>      _cairo_default_context_reset_static_data ();
>  
>  #if CAIRO_HAS_COGL_SURFACE
> Index: cairoint.h
> ===================================================================
> --- cairoint.h(cairo-1.14.6)
> +++ cairoint.h(working copy)
> @@ -442,6 +442,11 @@
>  cairo_private void
>  _cairo_win32_font_reset_static_data (void);
>  
> +#if CAIRO_HAS_WIN32_SURFACE
> +cairo_private void
> +_cairo_win32_device_reset_static_data (void);
> +#endif
> +
>  #if CAIRO_HAS_COGL_SURFACE
>  void
>  _cairo_cogl_context_reset_static_data (void);
> Index: win32/cairo-win32-device.c
> ===================================================================
> --- win32/cairo-win32-device.c(cairo-1.14.6)
> +++ win32/cairo-win32-device.c(working copy)
> @@ -187,3 +187,12 @@
>  
>      return flags;
>  }
> +
> +void _cairo_win32_device_reset_static_data (void)
> +{
> +     if (__cairo_win32_device != NULL) {
> +cairo_device_t *device = __cairo_win32_device;
> +__cairo_win32_device = NULL;
> +cairo_device_destroy (device);
> +    }
> +}
> 
> 
>
Thank you. The patch has been attached to the bug.

On Wed, Apr 6, 2016 at 12:51 AM, Adrian Johnson <ajohnson@redneon.com>
wrote:

> On 05/04/16 19:52, Fred Beca wrote:
> > Hi,
> >
> > There have been a memory leak on win32 platform for a while because of
> > the static __cairo_win32_device object that is never released
> > (see https://bugs.freedesktop.org/show_bug.cgi?id=67171)
> >
> > Please find attached a simple patch that fixes the problem by adding a
> > win32-specific cleanup call in the cairo_debug_reset_static_data
> > function. I hope it can be added to the official release to remove the
> leak.
>
> If you could add the patch to bug 67171 and I will test and commit it
> next time I am working on the windows backend.
>
> >
> > Regards,
> >
> > Fred
> >
> > Index: cairo-debug.c
> > ===================================================================
> > --- cairo-debug.c(cairo-1.14.6)
> > +++ cairo-debug.c(working copy)
> > @@ -89,7 +89,9 @@
> >  #if CAIRO_HAS_DRM_SURFACE
> >      _cairo_drm_device_reset_static_data ();
> >  #endif
> > -
> > +#if CAIRO_HAS_WIN32_SURFACE
> > +    _cairo_win32_device_reset_static_data ();
> > +#endif
> >      _cairo_default_context_reset_static_data ();
> >
> >  #if CAIRO_HAS_COGL_SURFACE
> > Index: cairoint.h
> > ===================================================================
> > --- cairoint.h(cairo-1.14.6)
> > +++ cairoint.h(working copy)
> > @@ -442,6 +442,11 @@
> >  cairo_private void
> >  _cairo_win32_font_reset_static_data (void);
> >
> > +#if CAIRO_HAS_WIN32_SURFACE
> > +cairo_private void
> > +_cairo_win32_device_reset_static_data (void);
> > +#endif
> > +
> >  #if CAIRO_HAS_COGL_SURFACE
> >  void
> >  _cairo_cogl_context_reset_static_data (void);
> > Index: win32/cairo-win32-device.c
> > ===================================================================
> > --- win32/cairo-win32-device.c(cairo-1.14.6)
> > +++ win32/cairo-win32-device.c(working copy)
> > @@ -187,3 +187,12 @@
> >
> >      return flags;
> >  }
> > +
> > +void _cairo_win32_device_reset_static_data (void)
> > +{
> > +     if (__cairo_win32_device != NULL) {
> > +cairo_device_t *device = __cairo_win32_device;
> > +__cairo_win32_device = NULL;
> > +cairo_device_destroy (device);
> > +    }
> > +}
> >
> >
> >
>
>