Remove useless checks for NULL before freeing
authorMatt Turner <mattst88@gmail.com>
Wed, 5 Sep 2012 06:33:28 +0000 (23:33 -0700)
committerMatt Turner <mattst88@gmail.com>
Thu, 6 Sep 2012 05:28:50 +0000 (22:28 -0700)
Same as earlier commit, except for "FREE"

This patch has been generated by the following Coccinelle semantic
patch:

// Remove useless checks for NULL before freeing
//
// free (NULL) is a no-op, so there is no need to avoid it

@@
expression E;
@@
+ FREE (E);
+ E = NULL;
- if (unlikely (E != NULL)) {
-   FREE(E);
(
-   E = NULL;
|
-   E = 0;
)
   ...
- }

@@
expression E;
type T;
@@
+ FREE ((T) E);
+ E = NULL;
- if (unlikely (E != NULL)) {
-   FREE((T) E);
(
-   E = NULL;
|
-   E = 0;
)
   ...
- }

@@
expression E;
@@
+ FREE (E);
- if (unlikely (E != NULL)) {
-   FREE (E);
- }

@@
expression E;
type T;
@@
+ FREE ((T) E);
- if (unlikely (E != NULL)) {
-   FREE ((T) E);
- }

Reviewed-by: Brian Paul <brianp@vmware.com>
28 files changed:
src/gallium/auxiliary/draw/draw_gs.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
src/gallium/auxiliary/tgsi/tgsi_exec.c
src/gallium/auxiliary/util/u_draw_quad.c
src/gallium/auxiliary/util/u_format.c
src/gallium/drivers/i915/i915_resource_texture.c
src/gallium/drivers/i915/i915_state.c
src/gallium/drivers/llvmpipe/lp_texture.c
src/gallium/drivers/nv30/nvfx_fragprog.c
src/gallium/drivers/nv50/nv50_program.c
src/gallium/drivers/nv50/nv50_screen.c
src/gallium/drivers/nvc0/nvc0_program.c
src/gallium/drivers/nvc0/nvc0_screen.c
src/gallium/drivers/r300/r300_screen_buffer.c
src/gallium/drivers/r300/r300_state.c
src/gallium/state_trackers/egl/common/egl_g3d.c
src/gallium/state_trackers/egl/drm/modeset.c
src/gallium/state_trackers/egl/drm/native_drm.c
src/gallium/state_trackers/egl/gdi/native_gdi.c
src/gallium/state_trackers/egl/wayland/native_drm.c
src/gallium/state_trackers/egl/wayland/native_shm.c
src/gallium/state_trackers/egl/x11/native_dri2.c
src/gallium/state_trackers/egl/x11/native_ximage.c
src/gallium/state_trackers/vega/text.c
src/gallium/state_trackers/wgl/stw_device.c
src/gallium/targets/graw-xlib/graw_xlib.c
src/gallium/winsys/sw/dri/dri_sw_winsys.c

index b2b40871af71e3eac7f5230b80b2e8837f69a312..c5647268595f364d5daf9585ae7c1e84e9499690 100644 (file)
@@ -435,9 +435,7 @@ int draw_geometry_shader_run(struct draw_geometry_shader *shader,
    shader->in_prim_idx = 0;
    shader->input_vertex_stride = input_stride;
    shader->input = input;
-   if (shader->primitive_lengths) {
-      FREE(shader->primitive_lengths);
-   }
+   FREE(shader->primitive_lengths);
    shader->primitive_lengths = MALLOC(max_out_prims * sizeof(unsigned));
 
    tgsi_exec_set_constant_buffers(machine, PIPE_MAX_CONSTANT_BUFFERS,
index fe96e5c9d49ceae43014ff912b28ece8a32867f7..453cf45b86e86c78aed3800adff7dbf821857f62 100644 (file)
@@ -287,8 +287,7 @@ if(mm->heap)
    u_mmDestroy(mm->heap);
    if(mm->map)
       pb_unmap(mm->buffer);
-   if(mm)
-      FREE(mm);
+   FREE(mm);
    return NULL;
 }
 
index a8e9a34d5194596ee5d60233ad1bccaa9cb80461..67a19fe8a689c5cea3acc025e401e7f9f384989c 100644 (file)
@@ -311,13 +311,11 @@ pool_bufmgr_create(struct pb_manager *provider,
    return SUPER(pool);
    
 failure:
-   if(pool->bufs)
-      FREE(pool->bufs);
+   FREE(pool->bufs);
    if(pool->map)
       pb_unmap(pool->buffer);
    if(pool->buffer)
       pb_reference(&pool->buffer, NULL);
-   if(pool)
-      FREE(pool);
+   FREE(pool);
    return NULL;
 }
index 5e23f5da65b718edf8865f0a9ef111e97b6824bc..68bb598cf3c3785a60823e71a1b0e824930458f6 100644 (file)
@@ -653,15 +653,11 @@ tgsi_exec_machine_bind_shader(
 
    if (!tokens) {
       /* unbind and free all */
-      if (mach->Declarations) {
-         FREE( mach->Declarations );
-      }
+      FREE(mach->Declarations);
       mach->Declarations = NULL;
       mach->NumDeclarations = 0;
 
-      if (mach->Instructions) {
-         FREE( mach->Instructions );
-      }
+      FREE(mach->Instructions);
       mach->Instructions = NULL;
       mach->NumInstructions = 0;
 
@@ -804,15 +800,11 @@ tgsi_exec_machine_bind_shader(
    }
    tgsi_parse_free (&parse);
 
-   if (mach->Declarations) {
-      FREE( mach->Declarations );
-   }
+   FREE(mach->Declarations);
    mach->Declarations = declarations;
    mach->NumDeclarations = numDeclarations;
 
-   if (mach->Instructions) {
-      FREE( mach->Instructions );
-   }
+   FREE(mach->Instructions);
    mach->Instructions = instructions;
    mach->NumInstructions = numInstructions;
 }
@@ -875,10 +867,8 @@ void
 tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach)
 {
    if (mach) {
-      if (mach->Instructions)
-         FREE(mach->Instructions);
-      if (mach->Declarations)
-         FREE(mach->Declarations);
+      FREE(mach->Instructions);
+      FREE(mach->Declarations);
 
       align_free(mach->Inputs);
       align_free(mach->Outputs);
index 469c874988db84937d23682d1cc8fae31480f21c..81c4f107ea9b4a6a04b0407a2906276fa9c11797 100644 (file)
@@ -151,6 +151,5 @@ out:
    if (vbuf)
       pipe_resource_reference(&vbuf, NULL);
    
-   if (v)
-      FREE(v);
+   FREE(v);
 }
index 6f4529835922d2e7483eaacca233b9ae9f88edce..a41c468a95d260956d61cce24c620c5eb26f6d47 100644 (file)
@@ -618,13 +618,9 @@ util_format_translate(enum pipe_format dst_format,
          src_row += src_step;
       }
 
-      if (tmp_s) {
-         FREE(tmp_s);
-      }
+      FREE(tmp_s);
 
-      if (tmp_z) {
-         FREE(tmp_z);
-      }
+      FREE(tmp_z);
 
       return;
    }
index e60b5b435cc2b7170835d556d2bb5dc2f8e8b464..603a379d0c87485da25316e8ba6c85e32efd52d5 100644 (file)
@@ -705,8 +705,7 @@ i915_texture_destroy(struct pipe_screen *screen,
       iws->buffer_destroy(iws, tex->buffer);
 
    for (i = 0; i < Elements(tex->image_offset); i++)
-      if (tex->image_offset[i])
-         FREE(tex->image_offset[i]);
+      FREE(tex->image_offset[i]);
 
    FREE(tex);
 }
index fdbff8b4a4e8eaf0ed3cdd9669260ebc66743d63..410615f212a121a959b5744c1d7720f0d2371eac 100644 (file)
@@ -614,10 +614,8 @@ void i915_delete_fs_state(struct pipe_context *pipe, void *shader)
 {
    struct i915_fragment_shader *ifs = (struct i915_fragment_shader *) shader;
 
-   if (ifs->decl) {
-      FREE(ifs->decl);
-      ifs->decl = NULL;
-   }
+   FREE(ifs->decl);
+   ifs->decl = NULL;
 
    if (ifs->program) {
       FREE(ifs->program);
@@ -625,6 +623,7 @@ void i915_delete_fs_state(struct pipe_context *pipe, void *shader)
       FREE((struct tgsi_token *)ifs->state.tokens);
       ifs->state.tokens = NULL;
    }
+
    ifs->program_len = 0;
    ifs->decl_len = 0;
 
index 36041432312ba20ad0aff5e6cf996c696f1ccfe5..924881c7030aa2057fbac21af32d84d93718d954 100644 (file)
@@ -184,9 +184,7 @@ llvmpipe_texture_layout(struct llvmpipe_screen *screen,
 
 fail:
    for (level = 0; level <= pt->last_level; level++) {
-      if (lpr->layout[level]) {
-         FREE(lpr->layout[level]);
-      }
+      FREE(lpr->layout[level]);
    }
 
    return FALSE;
index bfec4b3569bf7ee8c87f740634b94dbbec8c8035..935804e8e14f8c71c72ea8eefda14d44d6970d1b 100644 (file)
@@ -1101,10 +1101,9 @@ nvfx_fragprog_prepare(struct nv30_context* nvfx, struct nvfx_fpc *fpc)
    return TRUE;
 
 out_err:
-   if (fpc->r_temp) {
-      FREE(fpc->r_temp);
-      fpc->r_temp = NULL;
-   }
+   FREE(fpc->r_temp);
+   fpc->r_temp = NULL;
+
    tgsi_parse_free(&p);
    return FALSE;
 }
@@ -1218,8 +1217,7 @@ out:
    tgsi_parse_free(&parse);
    if(fpc)
    {
-      if (fpc->r_temp)
-         FREE(fpc->r_temp);
+      FREE(fpc->r_temp);
       util_dynarray_fini(&fpc->if_stack);
       util_dynarray_fini(&fpc->label_relocs);
       util_dynarray_fini(&fpc->imm_data);
index 72d14a6e3a0291334eef01c756aa53296d3becde..0d292f7ab891cbebcba6daeea05122198acdb418 100644 (file)
@@ -343,8 +343,7 @@ nv50_program_translate(struct nv50_program *prog, uint16_t chipset)
       NOUVEAU_ERR("shader translation failed: %i\n", ret);
       goto out;
    }
-   if (info->bin.syms) /* we don't need them yet */
-      FREE(info->bin.syms);
+   FREE(info->bin.syms);
 
    prog->code = info->bin.code;
    prog->code_size = info->bin.codeSize;
@@ -428,14 +427,11 @@ nv50_program_destroy(struct nv50_context *nv50, struct nv50_program *p)
    if (p->mem)
       nouveau_heap_free(&p->mem);
 
-   if (p->code)
-      FREE(p->code);
+   FREE(p->code);
 
-   if (p->fixups)
-      FREE(p->fixups);
+   FREE(p->fixups);
 
-   if (p->so)
-      FREE(p->so);
+   FREE(p->so);
 
    memset(p, 0, sizeof(*p));
 
index 3d510ea5f35645a85ba79e7514c9e7a74a00b1c1..beb81d664766a91ce3c6b5eb6db82cb45f4215b8 100644 (file)
@@ -267,8 +267,7 @@ nv50_screen_destroy(struct pipe_screen *pscreen)
    if (screen->base.pushbuf)
       screen->base.pushbuf->user_priv = NULL;
 
-   if (screen->blitctx)
-      FREE(screen->blitctx);
+   FREE(screen->blitctx);
 
    nouveau_bo_ref(NULL, &screen->code);
    nouveau_bo_ref(NULL, &screen->tls_bo);
@@ -281,8 +280,7 @@ nv50_screen_destroy(struct pipe_screen *pscreen)
    nouveau_heap_destroy(&screen->gp_code_heap);
    nouveau_heap_destroy(&screen->fp_code_heap);
 
-   if (screen->tic.entries)
-      FREE(screen->tic.entries);
+   FREE(screen->tic.entries);
 
    nouveau_object_del(&screen->tesla);
    nouveau_object_del(&screen->eng2d);
index f228d07bf6b42813ed8dab22eaa0afb9a9efe14b..9655e18de52d1441aa2bf80b395de887298b6cba 100644 (file)
@@ -574,8 +574,7 @@ nvc0_program_translate(struct nvc0_program *prog, uint16_t chipset)
       NOUVEAU_ERR("shader translation failed: %i\n", ret);
       goto out;
    }
-   if (info->bin.syms) /* we don't need them yet */
-      FREE(info->bin.syms);
+   FREE(info->bin.syms);
 
    prog->code = info->bin.code;
    prog->code_size = info->bin.codeSize;
@@ -752,12 +751,9 @@ 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);
-   if (prog->immd_data)
-      FREE(prog->immd_data);
-   if (prog->relocs)
-      FREE(prog->relocs);
+   FREE(prog->code);
+   FREE(prog->immd_data);
+   FREE(prog->relocs);
    if (prog->tfb) {
       if (nvc0->state.tfb == prog->tfb)
          nvc0->state.tfb = NULL;
index eb74e955f52e9f4a7bb3a2730371b885e28c2db2..d4487442a553942afdaa64d527925a8637c477f4 100644 (file)
@@ -256,8 +256,7 @@ nvc0_screen_destroy(struct pipe_screen *pscreen)
    if (screen->base.pushbuf)
       screen->base.pushbuf->user_priv = NULL;
 
-   if (screen->blitctx)
-      FREE(screen->blitctx);
+   FREE(screen->blitctx);
 
    nouveau_bo_ref(NULL, &screen->text);
    nouveau_bo_ref(NULL, &screen->uniform_bo);
@@ -269,8 +268,7 @@ nvc0_screen_destroy(struct pipe_screen *pscreen)
    nouveau_heap_destroy(&screen->lib_code);
    nouveau_heap_destroy(&screen->text_heap);
 
-   if (screen->tic.entries)
-      FREE(screen->tic.entries);
+   FREE(screen->tic.entries);
 
    nouveau_mm_destroy(screen->mm_VRAM_fe0);
 
index 7cb8cd60d3ec74a2f3545145b70dd7aabaca1862..f652bf72b0c2568b28a60157db805077ecf99dcc 100644 (file)
@@ -55,8 +55,7 @@ static void r300_buffer_destroy(struct pipe_screen *screen,
 {
     struct r300_resource *rbuf = r300_resource(buf);
 
-    if (rbuf->malloced_buffer)
-        FREE(rbuf->malloced_buffer);
+    FREE(rbuf->malloced_buffer);
 
     if (rbuf->buf)
         pb_reference(&rbuf->buf, NULL);
index 6f9feb105640934a88e1c9a0063f0b01693f54b2..46a6bf669b73209ed46b7ac6857308e2a90e9c78 100644 (file)
@@ -1840,8 +1840,7 @@ static void r300_delete_vs_state(struct pipe_context* pipe, void* shader)
 
     if (r300->screen->caps.has_tcl) {
         rc_constants_destroy(&vs->code.constants);
-        if (vs->code.constants_remap_table)
-            FREE(vs->code.constants_remap_table);
+        FREE(vs->code.constants_remap_table);
     } else {
         draw_delete_vertex_shader(r300->draw,
                 (struct draw_vertex_shader*)vs->draw_vs);
index 239be6129e8ba9a59aea9b305e6f7e5bd744d3eb..86abaebd70e52953ca4b835d7fc8565f3fc41134 100644 (file)
@@ -169,8 +169,7 @@ egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy)
    native_connectors =
       gdpy->native->modeset->get_connectors(gdpy->native, &num_connectors, NULL);
    if (!num_connectors) {
-      if (native_connectors)
-         FREE(native_connectors);
+      FREE(native_connectors);
       return;
    }
 
@@ -184,8 +183,7 @@ egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy)
       native_modes =
          gdpy->native->modeset->get_modes(gdpy->native, nconn, &num_modes);
       if (!num_modes) {
-         if (native_modes)
-            FREE(native_modes);
+         FREE(native_modes);
          continue;
       }
 
@@ -428,8 +426,7 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
 
    native_configs = gdpy->native->get_configs(gdpy->native, &num_configs);
    if (!num_configs) {
-      if (native_configs)
-         FREE(native_configs);
+      FREE(native_configs);
       return id;
    }
 
index b33323b9d60f9c5a7b637fa996764ff0e6f1b22c..32c0a258c6f84cc57ec1cdf05526c9118e7e4138 100644 (file)
@@ -648,10 +648,8 @@ drm_display_fini_modeset(struct native_display *ndpy)
       FREE(drmdpy->connectors);
    }
 
-   if (drmdpy->shown_surfaces) {
-      FREE(drmdpy->shown_surfaces);
-      drmdpy->shown_surfaces = NULL;
-   }
+   FREE(drmdpy->shown_surfaces);
+   drmdpy->shown_surfaces = NULL;
 
    if (drmdpy->saved_crtcs) {
       for (i = 0; i < drmdpy->resources->count_crtcs; i++) {
index feb1dc045bf1e8be8fca146dc5f8606d841062d4..23fc137b834a073139000b50bd58e5e2fdd44801 100644 (file)
@@ -123,8 +123,7 @@ drm_display_destroy(struct native_display *ndpy)
 {
    struct drm_display *drmdpy = drm_display(ndpy);
 
-   if (drmdpy->config)
-      FREE(drmdpy->config);
+   FREE(drmdpy->config);
 
    drm_display_fini_modeset(&drmdpy->base);
 
@@ -132,8 +131,7 @@ drm_display_destroy(struct native_display *ndpy)
    ndpy->screen = NULL;
    ndpy_uninit(ndpy);
 
-   if (drmdpy->device_name)
-      FREE(drmdpy->device_name);
+   FREE(drmdpy->device_name);
 
    if (drmdpy->own_gbm) {
       gbm_device_destroy(&drmdpy->gbmdrm->base.base);
index 78dbe7cca6c1c64951a312b0e51606b3fd1e0f1b..7b40108884ab685285d31e51acf9202fdb674a36 100644 (file)
@@ -358,8 +358,7 @@ gdi_display_destroy(struct native_display *ndpy)
 {
    struct gdi_display *gdpy = gdi_display(ndpy);
 
-   if (gdpy->configs)
-      FREE(gdpy->configs);
+   FREE(gdpy->configs);
 
    ndpy_uninit(ndpy);
 
index c6f61978ab07fb8015f3fdff1823e1831c4bf4c7..7255c8fc9e2927d8de3a46f1b1901acc6aa889ba 100644 (file)
@@ -73,10 +73,8 @@ wayland_drm_display_destroy(struct native_display *ndpy)
 
    if (drmdpy->wl_drm)
       wl_drm_destroy(drmdpy->wl_drm);
-   if (drmdpy->device_name)
-      FREE(drmdpy->device_name);
-   if (drmdpy->base.configs)
-      FREE(drmdpy->base.configs);
+   FREE(drmdpy->device_name);
+   FREE(drmdpy->base.configs);
    if (drmdpy->base.own_dpy)
       wl_display_disconnect(drmdpy->base.dpy);
 
index 574ffce4b6658854e7cbafe558744f01a8adcca3..643bb929af202143af4785efcce14a15bb63eaae 100644 (file)
@@ -63,8 +63,7 @@ wayland_shm_display_destroy(struct native_display *ndpy)
 {
    struct wayland_shm_display *shmdpy = wayland_shm_display(ndpy);
 
-   if (shmdpy->base.configs)
-      FREE(shmdpy->base.configs);
+   FREE(shmdpy->base.configs);
    if (shmdpy->base.own_dpy)
       wl_display_disconnect(shmdpy->base.dpy);
 
index 70ae0f984431ba3c7821535b0708d013b9b6c47d..a989f9e9108b35f34b114018d80f55c3904af433 100644 (file)
@@ -260,8 +260,7 @@ dri2_surface_get_buffers(struct native_surface *nsurf, uint buffer_mask)
    dri2surf->server_stamp++;
    dri2surf->client_stamp = dri2surf->server_stamp;
 
-   if (dri2surf->last_xbufs)
-      FREE(dri2surf->last_xbufs);
+   FREE(dri2surf->last_xbufs);
    dri2surf->last_xbufs = xbufs;
    dri2surf->last_num_xbufs = num_outs;
 }
@@ -432,8 +431,7 @@ dri2_surface_destroy(struct native_surface *nsurf)
    struct dri2_surface *dri2surf = dri2_surface(nsurf);
    int i;
 
-   if (dri2surf->last_xbufs)
-      FREE(dri2surf->last_xbufs);
+   FREE(dri2surf->last_xbufs);
 
    for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
       struct pipe_resource *ptex = dri2surf->textures[i];
@@ -752,8 +750,7 @@ dri2_display_destroy(struct native_display *ndpy)
 {
    struct dri2_display *dri2dpy = dri2_display(ndpy);
 
-   if (dri2dpy->configs)
-      FREE(dri2dpy->configs);
+   FREE(dri2dpy->configs);
 
    if (dri2dpy->base.screen)
       dri2dpy->base.screen->destroy(dri2dpy->base.screen);
index ae9c3b21356824e8ee0080e9443897ddef4667f4..4f09e4627c3ed4df78bb8eecbc9922f1fa795fd8 100644 (file)
@@ -511,8 +511,7 @@ ximage_display_destroy(struct native_display *ndpy)
 {
    struct ximage_display *xdpy = ximage_display(ndpy);
 
-   if (xdpy->configs)
-      FREE(xdpy->configs);
+   FREE(xdpy->configs);
 
    ndpy_uninit(ndpy);
 
index 27d461ce6601d32382499d724b01fef0426d9e0e..14e3cc575512cebbcce648754a44adcde2e23e79 100644 (file)
@@ -52,8 +52,7 @@ static VGboolean del_glyph(struct vg_font *font,
 
    glyph = (struct vg_glyph *)
       cso_hash_take(font->glyphs, (unsigned) glyphIndex);
-   if (glyph)
-      FREE(glyph);
+   FREE(glyph);
 
    return (glyph != NULL);
 }
index e65e71dc15fb58ac4ff25da7f387df5099e0709f..8e4459c67f7d19c5d60017ffdfc9813e0511124a 100644 (file)
@@ -117,8 +117,7 @@ stw_init(const struct stw_winsys *stw_winsys)
    return TRUE;
 
 error1:
-   if (stw_dev->smapi)
-      FREE(stw_dev->smapi);
+   FREE(stw_dev->smapi);
    if (stw_dev->stapi)
       stw_dev->stapi->destroy(stw_dev->stapi);
 
index 6138cf6c01a9bd2066c0682c0524d82c74336ae4..28277478064d7c249f1038a1b0aafb5b2fcdc319 100644 (file)
@@ -154,8 +154,7 @@ fail:
    if (screen)
       screen->destroy(screen);
 
-   if (xlib_handle)
-      FREE(xlib_handle);
+   FREE(xlib_handle);
 
    free(visinfo);
 
index 1bca827bd65f7d6bc80a4f114074336ade2ec411..edb3a381a749bbf769568eb66e239be9a187322d 100644 (file)
@@ -121,9 +121,7 @@ dri_sw_displaytarget_destroy(struct sw_winsys *ws,
 {
    struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt);
 
-   if (dri_sw_dt->data) {
-      FREE(dri_sw_dt->data);
-   }
+   FREE(dri_sw_dt->data);
 
    FREE(dri_sw_dt);
 }