[gegl] operations: Simplify code
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] operations: Simplify code
- Date: Mon, 30 Oct 2017 07:07:49 +0000 (UTC)
commit 5499882d02d30ee4be5d118639713e3f6933647c
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Oct 27 08:56:53 2017 +0200
operations: Simplify code
Leverage modern GLib API like g_clear_*, and the fact that g_free is
already NULL-safe.
https://bugzilla.gnome.org/show_bug.cgi?id=789543
operations/common-gpl3+/displace.c | 11 +++--------
operations/common/buffer-source.c | 3 +--
operations/common/color-temperature.c | 12 ++----------
operations/common/contrast-curve.c | 3 +--
operations/common/gegl.c | 6 ++----
operations/common/introspect.c | 6 +-----
operations/common/layer.c | 15 +++++----------
operations/common/magick-load.c | 6 +++---
operations/common/mantiuk06.c | 14 ++------------
operations/common/mblur.c | 4 +---
operations/common/save.c | 3 +--
operations/common/warp.c | 15 ++-------------
operations/common/watershed-transform.c | 7 ++-----
operations/common/write-buffer.c | 6 +-----
operations/core/cache.c | 6 +-----
operations/core/load.c | 3 +--
operations/external/ff-load.c | 15 +++++----------
operations/external/ff-save.c | 3 +--
operations/external/jp2-load.c | 11 +++--------
operations/external/jpg-load.c | 2 +-
operations/external/npy-save.c | 8 ++------
operations/external/path.c | 3 +--
operations/external/png-load.c | 10 ++++------
operations/external/raw-load.c | 3 +--
operations/external/sdl-display.c | 6 +-----
operations/external/svg-load.c | 4 +---
operations/external/text.c | 12 ++++--------
operations/external/tiff-load.c | 8 ++------
operations/external/tiff-save.c | 13 +++----------
operations/external/v4l.c | 4 ++--
operations/external/webp-load.c | 4 +---
operations/external/webp-save.c | 8 ++------
operations/seamless-clone/seamless-clone.c | 6 +-----
operations/transform/transform-core.c | 6 ++----
operations/workshop/bayer-matrix.c | 6 +-----
operations/workshop/external/v4l2.c | 3 +--
operations/workshop/gradient-map.c | 8 ++------
operations/workshop/median-blur.c | 6 +-----
38 files changed, 71 insertions(+), 198 deletions(-)
---
diff --git a/operations/common-gpl3+/displace.c b/operations/common-gpl3+/displace.c
index f7330c6..758853b 100644
--- a/operations/common-gpl3+/displace.c
+++ b/operations/common-gpl3+/displace.c
@@ -450,14 +450,9 @@ operation_process (GeglOperation *operation,
success = process (operation, input, aux, aux2, output, result, level);
}
- if (input != NULL)
- g_object_unref (input);
-
- if (aux != NULL)
- g_object_unref (aux);
-
- if (aux2 != NULL)
- g_object_unref (aux2);
+ g_clear_object (&input);
+ g_clear_object (&aux);
+ g_clear_object (&aux2);
return success;
}
diff --git a/operations/common/buffer-source.c b/operations/common/buffer-source.c
index 778f526..2818f06 100644
--- a/operations/common/buffer-source.c
+++ b/operations/common/buffer-source.c
@@ -189,8 +189,7 @@ dispose (GObject *object)
g_signal_handler_disconnect (o->buffer, p->buffer_changed_handler);
/* XXX: should decrement signal connected count */
- g_object_unref (o->buffer);
- o->buffer = NULL;
+ g_clear_object (&o->buffer);
}
if (p)
diff --git a/operations/common/color-temperature.c b/operations/common/color-temperature.c
index 73e92bf..cea0249 100644
--- a/operations/common/color-temperature.c
+++ b/operations/common/color-temperature.c
@@ -93,11 +93,7 @@ finalize (GObject *object)
{
GeglProperties *o = GEGL_PROPERTIES (object);
- if (o->user_data)
- {
- g_free (o->user_data);
- o->user_data = NULL;
- }
+ g_clear_pointer (&o->user_data, g_free);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
@@ -114,11 +110,7 @@ notify (GObject *object,
/* one of the properties has changed,
* invalidate the preprocessed coefficients
*/
- if (o->user_data)
- {
- g_free (o->user_data);
- o->user_data = NULL;
- }
+ g_clear_pointer (&o->user_data, g_free);
}
if (G_OBJECT_CLASS (gegl_op_parent_class)->notify)
diff --git a/operations/common/contrast-curve.c b/operations/common/contrast-curve.c
index 1edbc00..1c25bab 100644
--- a/operations/common/contrast-curve.c
+++ b/operations/common/contrast-curve.c
@@ -158,8 +158,7 @@ cl_process (GeglOperation *self,
g_free (ysf);
return FALSE;
error:
- if (ysf)
- g_free (ysf);
+ g_free (ysf);
if (cl_curve)
gegl_clReleaseMemObject (cl_curve);
diff --git a/operations/common/gegl.c b/operations/common/gegl.c
index e0484e0..f18e4fb 100644
--- a/operations/common/gegl.c
+++ b/operations/common/gegl.c
@@ -67,8 +67,7 @@ prepare (GeglOperation *operation)
if (!o->user_data || !g_str_equal (o->user_data, o->string))
{
- if (o->user_data)
- g_free (o->user_data);
+ g_free (o->user_data);
o->user_data = g_strdup (o->string);
input = gegl_node_get_input_proxy (gegl, "input");
@@ -86,8 +85,7 @@ prepare (GeglOperation *operation)
if (error)
{
gegl_node_set (gegl, "error", error->message, NULL);
- g_error_free (error);
- error = NULL;
+ g_clear_error (&error);
}
else
g_object_set (operation, "error", "", NULL);
diff --git a/operations/common/introspect.c b/operations/common/introspect.c
index b6334d1..4e6c1b9 100644
--- a/operations/common/introspect.c
+++ b/operations/common/introspect.c
@@ -92,11 +92,7 @@ gegl_introspect_dispose (GObject *object)
{
GeglProperties *o = GEGL_PROPERTIES (object);
- if (o->user_data != NULL)
- {
- g_object_unref (o->user_data);
- o->user_data = NULL;
- }
+ g_clear_object (&o->user_data);
G_OBJECT_CLASS (gegl_op_parent_class)->dispose (object);
}
diff --git a/operations/common/layer.c b/operations/common/layer.c
index d39bcd3..8c2c4ad 100644
--- a/operations/common/layer.c
+++ b/operations/common/layer.c
@@ -104,8 +104,7 @@ do_setup (GeglOperation *operation)
if (self->cached_path != NULL)
{
gegl_node_link (self->input, self->output);
- g_free (self->cached_path);
- self->cached_path = NULL;
+ g_clear_pointer (&self->cached_path, g_free);
}
return;
@@ -119,8 +118,7 @@ do_setup (GeglOperation *operation)
gegl_node_set (self->composite_op,
"operation", o->composite_op,
NULL);
- if (self->p_composite_op)
- g_free (self->p_composite_op);
+ g_free (self->p_composite_op);
self->p_composite_op = g_strdup (o->composite_op);
}
@@ -142,8 +140,7 @@ do_setup (GeglOperation *operation)
if (!self->cached_path)
gegl_node_link_many (self->input, self->composite_op, self->output, NULL);
- if (self->cached_path)
- g_free (self->cached_path);
+ g_free (self->cached_path);
self->cached_path = g_strdup (o->src);
}
@@ -243,10 +240,8 @@ finalize (GObject *object)
{
GeglOp *self = GEGL_OP (object);
- if (self->cached_path)
- g_free (self->cached_path);
- if (self->p_composite_op)
- g_free (self->p_composite_op);
+ g_free (self->cached_path);
+ g_free (self->p_composite_op);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
diff --git a/operations/common/magick-load.c b/operations/common/magick-load.c
index cff78ed..685bb57 100644
--- a/operations/common/magick-load.c
+++ b/operations/common/magick-load.c
@@ -116,9 +116,9 @@ static void finalize (GObject *object)
{
GeglOperation *op = (void*) object;
GeglProperties *o = GEGL_PROPERTIES (op);
- if (o->user_data)
- g_object_unref (o->user_data);
- o->user_data = NULL;
+
+ g_clear_object (&o->user_data);
+
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
diff --git a/operations/common/mantiuk06.c b/operations/common/mantiuk06.c
index 4fd171f..779cee3 100644
--- a/operations/common/mantiuk06.c
+++ b/operations/common/mantiuk06.c
@@ -431,7 +431,6 @@ mantiuk06_matrix_alloc (guint size)
static inline void
mantiuk06_matrix_free (gfloat *m)
{
- g_return_if_fail (m);
g_free (m);
}
@@ -650,17 +649,8 @@ mantiuk06_pyramid_free (pyramid_t *pyramid)
{
pyramid_t *const next = pyramid->next;
- if (pyramid->Gx != NULL)
- {
- g_free (pyramid->Gx);
- pyramid->Gx = NULL;
- }
-
- if (pyramid->Gy != NULL)
- {
- g_free (pyramid->Gy);
- pyramid->Gy = NULL;
- }
+ g_clear_pointer (&pyramid->Gx, g_free);
+ g_clear_pointer (&pyramid->Gy, g_free);
pyramid->prev = NULL;
pyramid->next = NULL;
diff --git a/operations/common/mblur.c b/operations/common/mblur.c
index f4e6878..3e05ec2 100644
--- a/operations/common/mblur.c
+++ b/operations/common/mblur.c
@@ -116,9 +116,7 @@ finalize (GObject *object)
Priv *p = (Priv*)o->user_data;
g_object_unref (p->acc);
-
- g_free (o->user_data);
- o->user_data = NULL;
+ g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
diff --git a/operations/common/save.c b/operations/common/save.c
index 4a22bed..214b6a6 100644
--- a/operations/common/save.c
+++ b/operations/common/save.c
@@ -174,8 +174,7 @@ gegl_save_dispose (GObject *object)
{
GeglOp *self = GEGL_OP (object);
- g_free (self->cached_path);
- self->cached_path = NULL;
+ g_clear_pointer (&self->cached_path, g_free);
G_OBJECT_CLASS (gegl_op_parent_class)->dispose (object);
}
diff --git a/operations/common/warp.c b/operations/common/warp.c
index 08c4e75..c07daab 100644
--- a/operations/common/warp.c
+++ b/operations/common/warp.c
@@ -98,19 +98,8 @@ clear_cache (GeglProperties *o)
if (! priv)
return;
- if (priv->lookup)
- {
- g_free (priv->lookup);
-
- priv->lookup = NULL;
- }
-
- if (priv->buffer)
- {
- g_object_unref (priv->buffer);
-
- priv->buffer = NULL;
- }
+ g_clear_pointer (&priv->lookup, g_free);
+ g_clear_object (&priv->buffer);
while (priv->processed_stroke)
{
diff --git a/operations/common/watershed-transform.c b/operations/common/watershed-transform.c
index 775d740..83400f0 100644
--- a/operations/common/watershed-transform.c
+++ b/operations/common/watershed-transform.c
@@ -353,11 +353,8 @@ operation_process (GeglOperation *operation,
success = process (operation, input, aux, output, result, level);
}
- if (input != NULL)
- g_object_unref (input);
-
- if (aux != NULL)
- g_object_unref (aux);
+ g_clear_object (&input);
+ g_clear_object (&aux);
return success;
}
diff --git a/operations/common/write-buffer.c b/operations/common/write-buffer.c
index a5d626e..a375e33 100644
--- a/operations/common/write-buffer.c
+++ b/operations/common/write-buffer.c
@@ -122,11 +122,7 @@ dispose (GObject *object)
{
GeglProperties *o = GEGL_PROPERTIES (object);
- if (o->buffer)
- {
- g_object_unref (o->buffer);
- o->buffer = NULL;
- }
+ g_clear_object (&o->buffer);
G_OBJECT_CLASS (gegl_op_parent_class)->dispose (object);
}
diff --git a/operations/core/cache.c b/operations/core/cache.c
index e306c5b..c630ae2 100644
--- a/operations/core/cache.c
+++ b/operations/core/cache.c
@@ -59,11 +59,7 @@ process (GeglOperation *operation,
if (o->cache != (void *) operation->node->cache)
{
- if (o->cache)
- {
- g_object_unref (o->cache);
- o->cache = NULL;
- }
+ g_clear_object (&o->cache);
if (operation->node->cache)
o->cache = g_object_ref (operation->node->cache);
diff --git a/operations/core/load.c b/operations/core/load.c
index 8cf9fb2..34e88c6 100644
--- a/operations/core/load.c
+++ b/operations/core/load.c
@@ -269,8 +269,7 @@ cleanup:
g_object_unref (stream);
}
- if (file != NULL)
- g_object_unref (file);
+ g_clear_object (&file);
g_free (buffer);
diff --git a/operations/external/ff-load.c b/operations/external/ff-load.c
index 8f9a668..22cb551 100644
--- a/operations/external/ff-load.c
+++ b/operations/external/ff-load.c
@@ -139,8 +139,7 @@ ff_cleanup (GeglProperties *o)
if (p)
{
clear_audio_track (o);
- if (p->loadedfilename)
- g_free (p->loadedfilename);
+ g_free (p->loadedfilename);
if (p->video_stream && p->video_stream->codec)
avcodec_close (p->video_stream->codec);
if (p->audio_stream && p->audio_stream->codec)
@@ -502,22 +501,19 @@ prepare (GeglOperation *operation)
p->height = p->video_stream->codec->height;
p->lavc_frame = av_frame_alloc ();
- if (o->video_codec)
- g_free (o->video_codec);
+ g_free (o->video_codec);
if (p->video_codec->name)
o->video_codec = g_strdup (p->video_codec->name);
else
o->video_codec = g_strdup ("");
- if (o->audio_codec)
- g_free (o->audio_codec);
+ g_free (o->audio_codec);
if (p->audio_codec && p->audio_codec->name)
o->audio_codec = g_strdup (p->audio_codec->name);
else
o->audio_codec = g_strdup ("");
- if (p->loadedfilename)
- g_free (p->loadedfilename);
+ g_free (p->loadedfilename);
p->loadedfilename = g_strdup (o->path);
p->prevframe = -1;
p->a_prevframe = -1;
@@ -750,8 +746,7 @@ finalize (GObject *object)
ff_cleanup (o);
g_free (p->loadedfilename);
- g_free (o->user_data);
- o->user_data = NULL;
+ g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
diff --git a/operations/external/ff-save.c b/operations/external/ff-save.c
index a3d46c7..90b6162 100644
--- a/operations/external/ff-save.c
+++ b/operations/external/ff-save.c
@@ -1085,8 +1085,7 @@ finalize (GObject *object)
avio_closep (&p->oc->pb);
avformat_free_context (p->oc);
- g_free (o->user_data);
- o->user_data = NULL;
+ g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)))->finalize (object);
diff --git a/operations/external/jp2-load.c b/operations/external/jp2-load.c
index 7364c4b..44ee336 100644
--- a/operations/external/jp2-load.c
+++ b/operations/external/jp2-load.c
@@ -461,11 +461,8 @@ process (GeglOperation *operation,
if (matrices[i])
jas_matrix_destroy (matrices[i]);
- if (data_b)
- g_free (data_b);
-
- if (data_s)
- g_free (data_s);
+ g_free (data_b);
+ g_free (data_s);
return ret;
}
@@ -501,9 +498,7 @@ finalize(GObject *object)
if (o->user_data != NULL)
{
cleanup(GEGL_OPERATION(object));
- if (o->user_data != NULL)
- g_free(o->user_data);
- o->user_data = NULL;
+ g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS(gegl_op_parent_class)->finalize(object);
diff --git a/operations/external/jpg-load.c b/operations/external/jpg-load.c
index 036511f..9e688a2 100644
--- a/operations/external/jpg-load.c
+++ b/operations/external/jpg-load.c
@@ -306,7 +306,7 @@ gegl_jpg_load_get_bounding_box (GeglOperation *operation)
gegl_operation_set_format (operation, "output", format);
g_object_unref(stream);
- if (file) g_object_unref(file);
+ g_clear_object(&file);
if (err || status)
return (GeglRectangle) {0, 0, 0, 0};
else
diff --git a/operations/external/npy-save.c b/operations/external/npy-save.c
index 89d7bc8..228fa2b 100644
--- a/operations/external/npy-save.c
+++ b/operations/external/npy-save.c
@@ -193,12 +193,8 @@ process (GeglOperation *operation,
}
cleanup:
- if (stream != NULL)
- g_object_unref (stream);
-
- if (file != NULL)
- g_object_unref (file);
-
+ g_clear_object (&stream);
+ g_clear_object (&file);
return status;
}
diff --git a/operations/external/path.c b/operations/external/path.c
index 8ea9f24..0f20528 100644
--- a/operations/external/path.c
+++ b/operations/external/path.c
@@ -243,8 +243,7 @@ gegl_path_stamp (GeglBuffer *buffer,
if (s.buf == NULL ||
s.radius != radius)
{
- if (s.buf != NULL)
- g_free (s.buf);
+ g_free (s.buf);
/* allocate a little bit more, just in case due to rounding errors and
* such */
s.buf = g_malloc (4*4* (roi.width + 2 ) * (roi.height + 2));
diff --git a/operations/external/png-load.c b/operations/external/png-load.c
index 96bf737..32df35b 100644
--- a/operations/external/png-load.c
+++ b/operations/external/png-load.c
@@ -207,8 +207,7 @@ gegl_buffer_import_png (GeglBuffer *gegl_buffer,
if (setjmp (png_jmpbuf (load_png_ptr)))
{
png_destroy_read_struct (&load_png_ptr, &load_info_ptr, NULL);
- if (row_p)
- g_free (row_p);
+ g_free (row_p);
return -1;
}
@@ -370,8 +369,7 @@ static gint query_png (GInputStream *stream,
if (setjmp (png_jmpbuf (load_png_ptr)))
{
png_destroy_read_struct (&load_png_ptr, &load_info_ptr, NULL);
- if (row_p)
- g_free (row_p);
+ g_free (row_p);
return -1;
}
@@ -436,7 +434,7 @@ get_bounding_box (GeglOperation *operation)
result.width = width;
result.height = height;
- if (infile) g_object_unref(infile);
+ g_clear_object(&infile);
g_object_unref(stream);
return result;
}
@@ -468,7 +466,7 @@ process (GeglOperation *operation,
G_OBJECT_TYPE_NAME (operation), o->path);
return FALSE;
}
- if (infile) g_object_unref(infile);
+ g_clear_object(&infile);
g_object_unref(stream);
return TRUE;
}
diff --git a/operations/external/raw-load.c b/operations/external/raw-load.c
index 3b71376..e6c9d7a 100644
--- a/operations/external/raw-load.c
+++ b/operations/external/raw-load.c
@@ -222,8 +222,7 @@ finalize (GObject *object)
if (o->user_data)
{
raw_close (o);
- g_free (o->user_data);
- o->user_data = NULL;
+ g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize(object);
diff --git a/operations/external/sdl-display.c b/operations/external/sdl-display.c
index a548fb2..e294416 100644
--- a/operations/external/sdl-display.c
+++ b/operations/external/sdl-display.c
@@ -142,11 +142,7 @@ finalize (GObject *object)
{
GeglProperties *o = GEGL_PROPERTIES (object);
- if (o->user_data)
- {
- g_free (o->user_data);
- o->user_data = NULL;
- }
+ g_clear_pointer (&o->user_data, g_free);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
diff --git a/operations/external/svg-load.c b/operations/external/svg-load.c
index 1215555..f8ed451 100644
--- a/operations/external/svg-load.c
+++ b/operations/external/svg-load.c
@@ -264,9 +264,7 @@ finalize (GObject *object)
if (o->user_data != NULL)
{
cleanup (GEGL_OPERATION (object));
- if (o->user_data != NULL)
- g_free (o->user_data);
- o->user_data = NULL;
+ g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
diff --git a/operations/external/text.c b/operations/external/text.c
index 62b9058..cddaa39 100644
--- a/operations/external/text.c
+++ b/operations/external/text.c
@@ -263,11 +263,9 @@ get_bounding_box (GeglOperation *operation)
cairo_destroy (cr);
cairo_surface_destroy (surface);
- if (extent->string)
- g_free (extent->string);
+ g_free (extent->string);
extent->string = g_strdup (o->string);
- if (extent->font)
- g_free (extent->font);
+ g_free (extent->font);
extent->font = g_strdup (o->font);
extent->size = o->size;
extent->wrap = o->wrap;
@@ -297,10 +295,8 @@ finalize (GObject *object)
{
GeglOp *self = GEGL_OP (object);
- if (self->cex.string)
- g_free (self->cex.string);
- if (self->cex.font)
- g_free (self->cex.font);
+ g_free (self->cex.string);
+ g_free (self->cex.font);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
diff --git a/operations/external/tiff-load.c b/operations/external/tiff-load.c
index ff1391f..cd85601 100644
--- a/operations/external/tiff-load.c
+++ b/operations/external/tiff-load.c
@@ -296,9 +296,7 @@ close_stream(thandle_t handle)
p->loaded = 0;
p->position = 0;
- if (p->buffer != NULL)
- g_free(p->buffer);
- p->buffer = NULL;
+ g_clear_pointer(&p->buffer, g_free);
p->allocated = 0;
@@ -847,9 +845,7 @@ finalize(GObject *object)
if (o->user_data != NULL)
{
cleanup(GEGL_OPERATION(object));
- if (o->user_data != NULL)
- g_free(o->user_data);
- o->user_data = NULL;
+ g_clear_pointer(&o->user_data, g_free);
}
G_OBJECT_CLASS(gegl_op_parent_class)->finalize(object);
diff --git a/operations/external/tiff-save.c b/operations/external/tiff-save.c
index 7f9923a..9add8c9 100644
--- a/operations/external/tiff-save.c
+++ b/operations/external/tiff-save.c
@@ -264,9 +264,7 @@ close_stream(thandle_t handle)
p->position = 0;
- if (p->buffer != NULL)
- g_free(p->buffer);
- p->buffer = NULL;
+ g_clear_pointer(&p->buffer, g_free);
p->allocated = 0;
@@ -594,13 +592,8 @@ process(GeglOperation *operation,
cleanup:
cleanup(operation);
- if (o->user_data != NULL)
- g_free(o->user_data);
- o->user_data = NULL;
-
- if (error != NULL)
- g_error_free(error);
-
+ g_clear_pointer(&o->user_data, g_free);
+ g_clear_error(&error);
return status;
}
diff --git a/operations/external/v4l.c b/operations/external/v4l.c
index 27f3417..0531e0d 100644
--- a/operations/external/v4l.c
+++ b/operations/external/v4l.c
@@ -196,8 +196,8 @@ finalize (GObject *object)
v4lclose (p->vd);
g_free (p->vd);
}
- g_free (o->user_data);
- o->user_data = NULL;
+
+ g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
diff --git a/operations/external/webp-load.c b/operations/external/webp-load.c
index cd6e63a..2f5b31a 100644
--- a/operations/external/webp-load.c
+++ b/operations/external/webp-load.c
@@ -317,9 +317,7 @@ finalize(GObject *object)
if (o->user_data != NULL)
{
cleanup (GEGL_OPERATION (object));
- if (o->user_data != NULL)
- g_free (o->user_data);
- o->user_data = NULL;
+ g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
diff --git a/operations/external/webp-save.c b/operations/external/webp-save.c
index 155855e..1349555 100644
--- a/operations/external/webp-save.c
+++ b/operations/external/webp-save.c
@@ -170,12 +170,8 @@ process (GeglOperation *operation,
}
cleanup:
- if (stream != NULL)
- g_object_unref (stream);
-
- if (file != NULL)
- g_object_unref (file);
-
+ g_clear_object (&stream);
+ g_clear_object (&file);
return status;
}
diff --git a/operations/seamless-clone/seamless-clone.c b/operations/seamless-clone/seamless-clone.c
index 22d5286..983a2bd 100644
--- a/operations/seamless-clone/seamless-clone.c
+++ b/operations/seamless-clone/seamless-clone.c
@@ -225,11 +225,7 @@ notify (GObject *object,
{
GeglProperties *o = GEGL_PROPERTIES (object);
- if (o->user_data)
- {
- g_free (o->user_data);
- o->user_data = NULL;
- }
+ g_clear_pointer (&o->user_data, g_free);
}
if (G_OBJECT_CLASS (gegl_op_parent_class)->notify)
diff --git a/operations/transform/transform-core.c b/operations/transform/transform-core.c
index d6a3ef1..7b99610 100644
--- a/operations/transform/transform-core.c
+++ b/operations/transform/transform-core.c
@@ -1180,8 +1180,7 @@ gegl_transform_process (GeglOperation *operation,
gegl_operation_context_take_object (context, "output", G_OBJECT (output));
- if (input != NULL)
- g_object_unref (input);
+ g_clear_object (&input);
}
else
{
@@ -1256,8 +1255,7 @@ gegl_transform_process (GeglOperation *operation,
func (operation, output, input, &matrix, result, level);
}
- if (input != NULL)
- g_object_unref (input);
+ g_clear_object (&input);
}
return TRUE;
diff --git a/operations/workshop/bayer-matrix.c b/operations/workshop/bayer-matrix.c
index 5aac779..b2a387a 100644
--- a/operations/workshop/bayer-matrix.c
+++ b/operations/workshop/bayer-matrix.c
@@ -145,11 +145,7 @@ finalize (GObject *object)
GeglOperation *op = (void*) object;
GeglProperties *o = GEGL_PROPERTIES (op);
- if (o->user_data)
- {
- g_free (o->user_data);
- o->user_data = NULL;
- }
+ g_clear_pointer (&o->user_data, g_free);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
diff --git a/operations/workshop/external/v4l2.c b/operations/workshop/external/v4l2.c
index 3fcf1e9..394fdc5 100644
--- a/operations/workshop/external/v4l2.c
+++ b/operations/workshop/external/v4l2.c
@@ -685,8 +685,7 @@ finalize (GObject *object)
close_device (p);
p->fd = 0;
}
- g_free (o->user_data);
- o->user_data = NULL;
+ g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
diff --git a/operations/workshop/gradient-map.c b/operations/workshop/gradient-map.c
index 1c20f41..f76e078 100644
--- a/operations/workshop/gradient-map.c
+++ b/operations/workshop/gradient-map.c
@@ -169,9 +169,7 @@ static void prepare (GeglOperation *operation)
o->user_data = props;
}
- if (props->gradient) {
- g_free(props->gradient);
- }
+ g_free(props->gradient);
props->gradient = create_linear_gradient(colors, stops, GRADIENT_STOPS,
gradient_length, gradient_channels, output_format);
}
@@ -182,9 +180,7 @@ static void finalize (GObject *object)
GeglProperties *o = GEGL_PROPERTIES (op);
if (o->user_data) {
GradientMapProperties *props = (GradientMapProperties *)o->user_data;
- if (props->gradient) {
- g_free(props->gradient);
- }
+ g_free(props->gradient);
o->user_data = NULL;
}
G_OBJECT_CLASS(gegl_op_parent_class)->finalize (object);
diff --git a/operations/workshop/median-blur.c b/operations/workshop/median-blur.c
index a756295..1590797 100644
--- a/operations/workshop/median-blur.c
+++ b/operations/workshop/median-blur.c
@@ -604,11 +604,7 @@ finalize (GObject *object)
GeglOperation *op = (void*) object;
GeglProperties *o = GEGL_PROPERTIES (op);
- if (o->user_data)
- {
- g_free (o->user_data);
- o->user_data = NULL;
- }
+ g_clear_pointer (&o->user_data, g_free);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]