Remove useless checks for NULL before freeing

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>
This commit is contained in:
Matt Turner 2012-09-04 23:33:28 -07:00
parent da3282b6e2
commit b6109de34f
28 changed files with 55 additions and 115 deletions

View 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,

View 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;
}

View 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;
}

View 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);

View File

@ -151,6 +151,5 @@ out:
if (vbuf)
pipe_resource_reference(&vbuf, NULL);
if (v)
FREE(v);
FREE(v);
}

View 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;
}

View 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);
}

View 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;

View 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;

View 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);

View 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));

View 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);

View 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;

View 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);

View 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);

View 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);

View 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;
}

View 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++) {

View 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);

View 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);

View 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);

View 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);

View 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);

View 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);

View 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);
}

View 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);

View File

@ -154,8 +154,7 @@ fail:
if (screen)
screen->destroy(screen);
if (xlib_handle)
FREE(xlib_handle);
FREE(xlib_handle);
free(visinfo);

View 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);
}