Remove useless checks for NULL before freeing
authorMatt Turner <mattst88@gmail.com>
Mon, 22 Sep 2014 04:13:33 +0000 (21:13 -0700)
committerMatt Turner <mattst88@gmail.com>
Tue, 9 Dec 2014 01:02:19 +0000 (17:02 -0800)
See commits 5067506e and b6109de3 for the Coccinelle script.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
20 files changed:
src/gallium/auxiliary/util/u_debug_flush.c
src/gallium/drivers/i915/i915_state.c
src/gallium/drivers/ilo/shader/toy_tgsi.c
src/gallium/drivers/nouveau/nv50/nv50_context.c
src/gallium/drivers/nouveau/nv50/nv84_video.c
src/gallium/drivers/nouveau/nvc0/nvc0_context.c
src/gallium/drivers/nouveau/nvc0/nvc0_program.c
src/gallium/drivers/nouveau/nvc0/nvc0_surface.c
src/gallium/drivers/r600/r600_isa.c
src/gallium/drivers/softpipe/sp_tile_cache.c
src/gallium/state_trackers/hgl/hgl.c
src/gallium/state_trackers/nine/nine_shader.c
src/gallium/state_trackers/nine/pixelshader9.c
src/gallium/state_trackers/nine/stateblock9.c
src/gallium/state_trackers/nine/swapchain9.c
src/gallium/state_trackers/nine/vertexdeclaration9.c
src/gallium/state_trackers/nine/vertexshader9.c
src/gallium/winsys/svga/drm/vmw_screen_ioctl.c
src/mesa/drivers/dri/common/xmlconfig.c
src/mesa/main/objectlabel.c

index fdb248c23afcc06bd298d823b2a72e077862cfbc..cdefca2fb11b3b0c674f651a8e63011b10408f4c 100644 (file)
@@ -132,8 +132,7 @@ debug_flush_buf_reference(struct debug_flush_buf **dst,
    struct debug_flush_buf *fbuf = *dst;
 
    if (pipe_reference(&(*dst)->reference, &src->reference)) {
-      if (fbuf->map_frame)
-         FREE(fbuf->map_frame);
+      FREE(fbuf->map_frame);
 
       FREE(fbuf);
    }
@@ -146,8 +145,7 @@ debug_flush_item_destroy(struct debug_flush_item *item)
 {
    debug_flush_buf_reference(&item->fbuf, NULL);
 
-   if (item->ref_frame)
-      FREE(item->ref_frame);
+   FREE(item->ref_frame);
 
    FREE(item);
 }
@@ -263,10 +261,8 @@ debug_flush_unmap(struct debug_flush_buf *fbuf)
 
    fbuf->mapped_sync = FALSE;
    fbuf->mapped = FALSE;
-   if (fbuf->map_frame) {
-      FREE(fbuf->map_frame);
-      fbuf->map_frame = NULL;
-   }
+   FREE(fbuf->map_frame);
+   fbuf->map_frame = NULL;
    pipe_mutex_unlock(fbuf->mutex);
 }
 
index c90fcfd74919e08e11fb72d2bd64078b8b0b6fd2..6ba9646f7ab661f7c3b7392c124ebb6567951f96 100644 (file)
@@ -628,12 +628,10 @@ void i915_delete_fs_state(struct pipe_context *pipe, void *shader)
    FREE(ifs->decl);
    ifs->decl = NULL;
 
-   if (ifs->program) {
-      FREE(ifs->program);
-      ifs->program = NULL;
-      FREE((struct tgsi_token *)ifs->state.tokens);
-      ifs->state.tokens = NULL;
-   }
+   FREE(ifs->program);
+   ifs->program = NULL;
+   FREE((struct tgsi_token *)ifs->state.tokens);
+   ifs->state.tokens = NULL;
 
    ifs->program_len = 0;
    ifs->decl_len = 0;
index 57501eac337431e6e8272d81d792190178fd9a16..65e47bf3a4ab15c50e22d9cdbab83bfe69bc3d2b 100644 (file)
@@ -2296,10 +2296,8 @@ add_imm(struct toy_tgsi *tgsi, enum toy_type type, const uint32_t *buf)
             cur_size * sizeof(new_types[0]),
             new_size * sizeof(new_types[0]));
       if (!new_buf || !new_types) {
-         if (new_buf)
-            FREE(new_buf);
-         if (new_types)
-            FREE(new_types);
+         FREE(new_buf);
+         FREE(new_types);
          return -1;
       }
 
index 1a53579b49d4d2459b0bb106ca03d0a3c112ec0e..2cfd5db5ea030fdd3d1d0e8b228ecd26ddbb7e5c 100644 (file)
@@ -338,8 +338,7 @@ out_err:
       nouveau_bufctx_del(&nv50->bufctx_3d);
    if (nv50->bufctx)
       nouveau_bufctx_del(&nv50->bufctx);
-   if (nv50->blit)
-      FREE(nv50->blit);
+   FREE(nv50->blit);
    FREE(nv50);
    return NULL;
 }
index 395bd7a355b42933487e38c7b63d11db0eb62016..7a4670f663db027ed8a00189295efd4844423d37 100644 (file)
@@ -256,8 +256,7 @@ nv84_decoder_destroy(struct pipe_video_codec *decoder)
 
    nouveau_client_del(&dec->client);
 
-   if (dec->mpeg12_bs)
-      FREE(dec->mpeg12_bs);
+   FREE(dec->mpeg12_bs);
    FREE(dec);
 }
 
index 3992460eb4af3419403e518260e8c601ec17e9ba..7662fb50f615baf14fa35e4bec1672ae7ba3c447 100644 (file)
@@ -365,8 +365,7 @@ out_err:
          nouveau_bufctx_del(&nvc0->bufctx_cp);
       if (nvc0->bufctx)
          nouveau_bufctx_del(&nvc0->bufctx);
-      if (nvc0->blit)
-         FREE(nvc0->blit);
+      FREE(nvc0->blit);
       FREE(nvc0);
    }
    return NULL;
index 21be8b7240ea47d21c5e33036286dd3d34ac135d..c156e918dc56916fee57858d5e14af22ba440fb4 100644 (file)
@@ -783,8 +783,7 @@ nvc0_program_destroy(struct nvc0_context *nvc0, struct nvc0_program *prog)
 
    if (prog->mem)
       nouveau_heap_free(&prog->mem);
-   if (prog->code)
-      FREE(prog->code); /* may be 0 for hardcoded shaders */
+   FREE(prog->code); /* may be 0 for hardcoded shaders */
    FREE(prog->immd_data);
    FREE(prog->relocs);
    if (prog->type == PIPE_SHADER_COMPUTE && prog->cp.syms)
index 17fe66d58dbaf8c2305bc7ea76ce1481fa71be5c..980fd1285a60a2d20b3c7ed074b25f758c47a329 100644 (file)
@@ -1501,8 +1501,7 @@ nvc0_blitctx_create(struct nvc0_context *nvc0)
 void
 nvc0_blitctx_destroy(struct nvc0_context *nvc0)
 {
-   if (nvc0->blit)
-      FREE(nvc0->blit);
+   FREE(nvc0->blit);
 }
 
 void
index 81544ca3dd1a43a768c3c6b215e170f203a3e3f7..4ea71035c7939435113aa1dd6f1dc5b7ee861af9 100644 (file)
@@ -89,14 +89,10 @@ int r600_isa_destroy(struct r600_isa *isa) {
        if (!isa)
                return 0;
 
-       if (isa->alu_op2_map)
-               free(isa->alu_op2_map);
-       if (isa->alu_op3_map)
-               free(isa->alu_op3_map);
-       if (isa->fetch_map)
-               free(isa->fetch_map);
-       if (isa->cf_map)
-               free(isa->cf_map);
+       free(isa->alu_op2_map);
+       free(isa->alu_op3_map);
+       free(isa->fetch_map);
+       free(isa->cf_map);
 
        free(isa);
        return 0;
index 78534b55902619dd8b5bd35bb50f1493f42d8c9e..b763f526e6139f5b7ce4cc2c2f179c664af05be6 100644 (file)
@@ -186,8 +186,7 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc,
       FREE(tc->transfer_map);
       tc->num_maps = 0;
 
-      if (tc->clear_flags)
-         FREE(tc->clear_flags);
+      FREE(tc->clear_flags);
       tc->clear_flags_size = 0;
    }
 
index ce2ffb1d418833cfa277e5564bdf6a5e79754c2c..4d7c479e6163fb98d006d91cce46da17aad859c1 100644 (file)
@@ -214,8 +214,7 @@ hgl_destroy_st_manager(struct st_manager *manager)
 {
        CALLED();
 
-       if (manager)
-               FREE(manager);
+       FREE(manager);
 }
 
 
@@ -313,6 +312,5 @@ hgl_destroy_st_visual(struct st_visual* visual)
 {
        CALLED();
 
-       if (visual)
-               FREE(visual);
+       FREE(visual);
 }
index 3c39b246101bb235ed0edfc64e7dce14318c55aa..c2a0f4dbd9da2b6dfd57ff5ffab021df3c8f622e 100644 (file)
@@ -2767,10 +2767,8 @@ tx_dtor(struct shader_translator *tx)
 {
     if (tx->num_inst_labels)
         FREE(tx->inst_labels);
-    if (tx->lconstf)
-        FREE(tx->lconstf);
-    if (tx->regs.r)
-        FREE(tx->regs.r);
+    FREE(tx->lconstf);
+    FREE(tx->regs.r);
     FREE(tx);
 }
 
index d567bcb4a0bdc2030aa628db11358b74078c5256..ac204ff5785c9e08651dbf155a1bcff60d72935b 100644 (file)
@@ -98,8 +98,7 @@ NinePixelShader9_dtor( struct NinePixelShader9 *This )
     }
     nine_shader_variants_free(&This->variant);
 
-    if (This->byte_code.tokens)
-        FREE((void *)This->byte_code.tokens); /* const_cast */
+    FREE((void *)This->byte_code.tokens); /* const_cast */
 
     FREE(This->lconstf.data);
     FREE(This->lconstf.ranges);
index cb096c7fc1a7208916e345c916e8927f6e958269..36b5e7773cad263c3eb0d391d3028f5f1aadc97e 100644 (file)
@@ -60,12 +60,12 @@ NineStateBlock9_dtor( struct NineStateBlock9 *This )
 
     nine_state_clear(state, FALSE);
 
-    if (state->vs_const_f) FREE(state->vs_const_f);
-    if (state->ps_const_f) FREE(state->ps_const_f);
+    FREE(state->vs_const_f);
+    FREE(state->ps_const_f);
 
-    if (state->ff.light) FREE(state->ff.light);
+    FREE(state->ff.light);
 
-    if (state->ff.transform) FREE(state->ff.transform);
+    FREE(state->ff.transform);
 
     if (This->state.changed.ps_const_f) {
         for (r = This->state.changed.ps_const_f; r->next; r = r->next);
index a7868ca3aa397bba40ec66975d3fec31e1f2f420..bf87aaf042ea8b20bb220a15342cec7f6549819d 100644 (file)
@@ -177,7 +177,7 @@ NineSwapChain9_Resize( struct NineSwapChain9 *This,
     } else if (mode) {
         This->mode = malloc(sizeof(D3DDISPLAYMODEEX));
         memcpy(This->mode, mode, sizeof(D3DDISPLAYMODEEX));
-    } else if (This->mode) {
+    } else {
         free(This->mode);
         This->mode = NULL;
     }
index 49a60e35b1ea7948f015d03174cb27603d1dca5d..4aea1169be317c465d81b198b77b4364b4b2798e 100644 (file)
@@ -220,12 +220,9 @@ NineVertexDeclaration9_ctor( struct NineVertexDeclaration9 *This,
 void
 NineVertexDeclaration9_dtor( struct NineVertexDeclaration9 *This )
 {
-    if (This->decls)
-        FREE(This->decls);
-    if (This->elems)
-        FREE(This->elems);
-    if (This->usage_map)
-        FREE(This->usage_map);
+    FREE(This->decls);
+    FREE(This->elems);
+    FREE(This->usage_map);
 
     NineUnknown_dtor(&This->base);
 }
index d8507b5cccc8ce854feabb9948243f3b760039e6..3d40d60c0620d2c33707165ef499797cfbbfd5db 100644 (file)
@@ -105,8 +105,7 @@ NineVertexShader9_dtor( struct NineVertexShader9 *This )
     }
     nine_shader_variants_free(&This->variant);
 
-    if (This->byte_code.tokens)
-        FREE((void *)This->byte_code.tokens); /* const_cast */
+    FREE((void *)This->byte_code.tokens); /* const_cast */
 
     FREE(This->lconstf.data);
     FREE(This->lconstf.ranges);
index c9a3b7544d2649c7445dbafe3f09c0cbc3bec92f..14c3b2068c6bc6ed3d968a87a49f56799d9cebac 100644 (file)
@@ -248,8 +248,7 @@ vmw_ioctl_gb_surface_create(struct vmw_winsys_screen *vws,
    return rep->handle;
 
 out_fail_create:
-   if (region)
-      FREE(region);
+   FREE(region);
    return SVGA3D_INVALID_ID;
 }
 
@@ -378,8 +377,7 @@ out_fail_ref:
    if (needs_unref)
       vmw_ioctl_surface_destroy(vws, *handle);
 out_fail_req:
-   if (region)
-      FREE(region);
+   FREE(region);
    return ret;
 }
 
index 8e48522e2e7a0040eac204818d5e5927000b1dd4..d69eb0196d35bfdfea44024d91c62ebd7e89251f 100644 (file)
@@ -312,8 +312,7 @@ static unsigned char parseValue (driOptionValue *v, driOptionType type,
        v->_float = strToF (string, &tail);
        break;
       case DRI_STRING:
-       if (v->_string)
-           free (v->_string);
+       free (v->_string);
        v->_string = strndup(string, STRING_CONF_MAXLEN);
        return GL_TRUE;
     }
index 8efc33e0dd0799bdd3271718fecd26824ad366f7..efa7ba8d19a5e691cbcc81a9395b3b1db4b28f94 100644 (file)
@@ -45,11 +45,8 @@ static void
 set_label(struct gl_context *ctx, char **labelPtr, const char *label,
           int length, const char *caller)
 {
-   if (*labelPtr) {
-      /* free old label string */
-      free(*labelPtr);
-      *labelPtr = NULL;
-   }
+   free(*labelPtr);
+   *labelPtr = NULL;
 
    /* set new label string */
    if (label) {