[Spice-devel] [PATCH 02/17] Remove useless if() before free()
Alon Levy
alevy at redhat.com
Thu Jan 12 03:31:36 PST 2012
On Tue, Jan 10, 2012 at 03:58:23PM +0000, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at redhat.com>
>
> The free() function allows NULL to be passed in, so any
> code which puts a if() before free() is wasting time
Cool, even removes some inconsistent paren use. ACK.
> ---
> common/canvas_base.c | 8 ++------
> common/canvas_utils.c | 4 +---
> common/gdi_canvas.c | 4 +---
> common/gl_canvas.c | 4 +---
> common/lines.c | 15 +++++----------
> common/mem.c | 4 +---
> common/sw_canvas.c | 4 +---
> server/mjpeg_encoder.c | 3 +--
> server/red_parse_qxl.c | 4 +---
> server/red_worker.c | 4 +---
> server/tests/test_display_base.c | 4 +---
> 11 files changed, 16 insertions(+), 42 deletions(-)
>
> diff --git a/common/canvas_base.c b/common/canvas_base.c
> index d11c8ec..16688fb 100644
> --- a/common/canvas_base.c
> +++ b/common/canvas_base.c
> @@ -749,9 +749,7 @@ static pixman_image_t *canvas_get_lz(CanvasBase *canvas, SpiceImage *image, int
> int free_palette;
>
> if (setjmp(lz_data->jmp_env)) {
> - if (decomp_buf) {
> - free(decomp_buf);
> - }
> + free(decomp_buf);
> CANVAS_ERROR("lz error, %s", lz_data->message_buf);
> }
>
> @@ -3134,9 +3132,7 @@ static void canvas_draw_stroke(SpiceCanvas *spice_canvas, SpiceRect *bbox,
>
> stroke_lines_draw(&lines, (lineGC *)&gc, dashed);
>
> - if (gc.base.dash) {
> - free(gc.base.dash);
> - }
> + free(gc.base.dash);
> stroke_lines_free(&lines);
>
> if (!gc.solid && gc.tile && !surface_canvas) {
> diff --git a/common/canvas_utils.c b/common/canvas_utils.c
> index 55b7159..71f6890 100644
> --- a/common/canvas_utils.c
> +++ b/common/canvas_utils.c
> @@ -51,9 +51,7 @@ static void release_data(pixman_image_t *image, void *release_data)
> gdi_handlers--;
> }
> #endif
> - if (data->data) {
> - free(data->data);
> - }
> + free(data->data);
>
> free(data);
> }
> diff --git a/common/gdi_canvas.c b/common/gdi_canvas.c
> index fe2ac5d..5200cf9 100644
> --- a/common/gdi_canvas.c
> +++ b/common/gdi_canvas.c
> @@ -1775,9 +1775,7 @@ static void gdi_canvas_draw_stroke(SpiceCanvas *spice_canvas, SpiceRect *bbox, S
> }
> #endif
>
> - if (user_style) {
> - free(user_style);
> - }
> + free(user_style);
> }
>
> static void gdi_canvas_clear(SpiceCanvas *spice_canvas)
> diff --git a/common/gl_canvas.c b/common/gl_canvas.c
> index a04740b..ffc6b52 100644
> --- a/common/gl_canvas.c
> +++ b/common/gl_canvas.c
> @@ -870,9 +870,7 @@ static void gl_canvas_destroy(SpiceCanvas *spice_canvas)
> }
> canvas_base_destroy(&canvas->base);
> glc_destroy(canvas->glc, canvas->textures_lost);
> - if (canvas->private_data) {
> - free(canvas->private_data);
> - }
> + free(canvas->private_data);
> free(canvas);
> }
>
> diff --git a/common/lines.c b/common/lines.c
> index e2349e8..9b47ee3 100644
> --- a/common/lines.c
> +++ b/common/lines.c
> @@ -580,8 +580,7 @@ miAppendSpans (SpanGroup * spanGroup, SpanGroup * otherGroup, Spans * spans)
> static void
> miFreeSpanGroup (SpanGroup * spanGroup)
> {
> - if (spanGroup->group != NULL)
> - xfree (spanGroup->group);
> + xfree (spanGroup->group);
> }
>
> static void
> @@ -776,10 +775,8 @@ miFillUniqueSpanGroup (GCPtr pGC, SpanGroup * spanGroup, Boolean foreground)
> ysizes = (int *)xalloc (ylength * sizeof (int));
>
> if (!yspans || !ysizes) {
> - if (yspans)
> - xfree (yspans);
> - if (ysizes)
> - xfree (ysizes);
> + xfree (yspans);
> + xfree (ysizes);
> miDisposeSpanGroup (spanGroup);
> return;
> }
> @@ -849,10 +846,8 @@ miFillUniqueSpanGroup (GCPtr pGC, SpanGroup * spanGroup, Boolean foreground)
> }
> xfree (yspans);
> xfree (ysizes);
> - if (points)
> - xfree (points);
> - if (widths)
> - xfree (widths);
> + xfree (points);
> + xfree (widths);
> return;
> }
> count = 0;
> diff --git a/common/mem.c b/common/mem.c
> index 7236cf0..5298e37 100644
> --- a/common/mem.c
> +++ b/common/mem.c
> @@ -130,9 +130,7 @@ void *spice_realloc(void *mem, size_t n_bytes)
> (unsigned long)n_bytes);
> }
>
> - if (mem) {
> - free(mem);
> - }
> + free(mem);
>
> return NULL;
> }
> diff --git a/common/sw_canvas.c b/common/sw_canvas.c
> index 287fdf2..3a75e48 100644
> --- a/common/sw_canvas.c
> +++ b/common/sw_canvas.c
> @@ -1163,9 +1163,7 @@ static void canvas_destroy(SpiceCanvas *spice_canvas)
> }
> pixman_image_unref(canvas->image);
> canvas_base_destroy(&canvas->base);
> - if (canvas->private_data) {
> - free(canvas->private_data);
> - }
> + free(canvas->private_data);
> free(canvas);
> }
>
> diff --git a/server/mjpeg_encoder.c b/server/mjpeg_encoder.c
> index 599d4f5..6b68549 100644
> --- a/server/mjpeg_encoder.c
> +++ b/server/mjpeg_encoder.c
> @@ -129,8 +129,7 @@ static boolean empty_mem_output_buffer(j_compress_ptr cinfo)
>
> memcpy(nextbuffer, dest->buffer, dest->bufsize);
>
> - if (dest->newbuffer != NULL)
> - free(dest->newbuffer);
> + free(dest->newbuffer);
>
> dest->newbuffer = nextbuffer;
>
> diff --git a/server/red_parse_qxl.c b/server/red_parse_qxl.c
> index 743a82d..256e8e9 100644
> --- a/server/red_parse_qxl.c
> +++ b/server/red_parse_qxl.c
> @@ -409,9 +409,7 @@ void red_put_image(SpiceImage *red)
>
> switch (red->descriptor.type) {
> case SPICE_IMAGE_TYPE_BITMAP:
> - if (red->u.bitmap.palette) {
> - free(red->u.bitmap.palette);
> - }
> + free(red->u.bitmap.palette);
> spice_chunks_destroy(red->u.bitmap.data);
> break;
> case SPICE_IMAGE_TYPE_QUIC:
> diff --git a/server/red_worker.c b/server/red_worker.c
> index e2c2393..b312fcc 100644
> --- a/server/red_worker.c
> +++ b/server/red_worker.c
> @@ -2468,9 +2468,7 @@ static void red_display_release_stream_clip(RedWorker *worker, StreamClipItem *i
> {
> if (!--item->refs) {
> red_display_release_stream(worker, item->stream_agent);
> - if (item->rects) {
> - free(item->rects);
> - }
> + free(item->rects);
> free(item);
> }
> }
> diff --git a/server/tests/test_display_base.c b/server/tests/test_display_base.c
> index 81f942b..579ef1e 100644
> --- a/server/tests/test_display_base.c
> +++ b/server/tests/test_display_base.c
> @@ -29,9 +29,7 @@ static void test_spice_destroy_update(SimpleSpiceUpdate *update)
> if (!update) {
> return;
> }
> - if (update->bitmap) {
> - free(update->bitmap);
> - }
> + free(update->bitmap);
> free(update);
> }
>
> --
> 1.7.7.5
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
More information about the Spice-devel
mailing list