[mutter/gnome-3-36] cogl: Use autopointers to free structs on return
- From: Robert Mader <rmader src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gnome-3-36] cogl: Use autopointers to free structs on return
- Date: Fri, 7 Aug 2020 11:19:42 +0000 (UTC)
commit 143771441fc05f61cdaa0351d37afd9172a3b2f5
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Tue Jul 9 11:13:09 2019 +0200
cogl: Use autopointers to free structs on return
This is a potential leak discovered by static analysis, in fact if
_COGL_GET_CONTEXT returns, the newly allocated struct isn't released.
https://gitlab.gnome.org/GNOME/mutter/merge_requests/1195
(cherry picked from commit 645d596f9d39e26c239a307fa699f11eeb921e18)
cogl/cogl-pango/cogl-pango-fontmap.c | 4 ++--
cogl/cogl/cogl-onscreen.c | 4 +++-
cogl/cogl/cogl-pipeline-cache.c | 4 ++--
3 files changed, 7 insertions(+), 5 deletions(-)
---
diff --git a/cogl/cogl-pango/cogl-pango-fontmap.c b/cogl/cogl-pango/cogl-pango-fontmap.c
index 0c43909c71..714ba65463 100644
--- a/cogl/cogl-pango/cogl-pango-fontmap.c
+++ b/cogl/cogl-pango/cogl-pango-fontmap.c
@@ -74,7 +74,7 @@ PangoFontMap *
cogl_pango_font_map_new (void)
{
PangoFontMap *fm = pango_cairo_font_map_new ();
- CoglPangoFontMapPriv *priv = g_new0 (CoglPangoFontMapPriv, 1);
+ g_autofree CoglPangoFontMapPriv *priv = g_new0 (CoglPangoFontMapPriv, 1);
_COGL_GET_CONTEXT (context, NULL);
@@ -85,7 +85,7 @@ cogl_pango_font_map_new (void)
* for now. */
g_object_set_qdata_full (G_OBJECT (fm),
cogl_pango_font_map_get_priv_key (),
- priv,
+ g_steal_pointer (&priv),
free_priv);
return fm;
diff --git a/cogl/cogl/cogl-onscreen.c b/cogl/cogl/cogl-onscreen.c
index 1bd1d59118..704e1c44bd 100644
--- a/cogl/cogl/cogl-onscreen.c
+++ b/cogl/cogl/cogl-onscreen.c
@@ -93,10 +93,12 @@ _cogl_onscreen_init_from_template (CoglOnscreen *onscreen,
CoglOnscreen *
_cogl_onscreen_new (void)
{
- CoglOnscreen *onscreen = g_new0 (CoglOnscreen, 1);
+ g_autofree CoglOnscreen *onscreen_ptr = g_new0 (CoglOnscreen, 1);
+ CoglOnscreen *onscreen;
_COGL_GET_CONTEXT (ctx, NULL);
+ onscreen = g_steal_pointer (&onscreen_ptr);
_cogl_framebuffer_init (COGL_FRAMEBUFFER (onscreen),
ctx,
COGL_FRAMEBUFFER_TYPE_ONSCREEN,
diff --git a/cogl/cogl/cogl-pipeline-cache.c b/cogl/cogl/cogl-pipeline-cache.c
index 216add80ff..6bfc37732a 100644
--- a/cogl/cogl/cogl-pipeline-cache.c
+++ b/cogl/cogl/cogl-pipeline-cache.c
@@ -50,7 +50,7 @@ struct _CoglPipelineCache
CoglPipelineCache *
_cogl_pipeline_cache_new (void)
{
- CoglPipelineCache *cache = g_new (CoglPipelineCache, 1);
+ g_autofree CoglPipelineCache *cache = g_new (CoglPipelineCache, 1);
unsigned long vertex_state;
unsigned long layer_vertex_state;
unsigned int fragment_state;
@@ -80,7 +80,7 @@ _cogl_pipeline_cache_new (void)
layer_vertex_state | layer_fragment_state,
"programs");
- return cache;
+ return g_steal_pointer (&cache);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]