Remove useless checks for NULL before freeing

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;
@@
+ free (E);
- if (unlikely (E != NULL)) {
-   free (E);
- }
This commit is contained in:
Andrea Canciani 2011-07-30 11:04:16 +02:00
parent 8f8da19fd4
commit e04e368748
28 changed files with 88 additions and 168 deletions

View file

@ -505,8 +505,7 @@ cairo_perf_report_load (cairo_perf_report_t *report,
/* Do nothing on TEST_REPORT_STATUS_COMMENT */
}
if (line)
free (line);
free (line);
if (filename != NULL)
fclose (file);

View file

@ -614,8 +614,7 @@ read_excludes (cairo_perf_t *perf,
perf->num_exclude_names++;
}
}
if (line != NULL)
free (line);
free (line);
fclose (file);

View file

@ -2702,10 +2702,8 @@ fail3:
free (font->subset_font_name);
fail2:
free (font->data);
if (font->font_name)
free (font->font_name);
if (font->ps_name)
free (font->ps_name);
free (font->font_name);
free (font->ps_name);
_cairo_array_fini (&font->output);
fail1:
free (font);
@ -2719,8 +2717,7 @@ cairo_cff_font_destroy (cairo_cff_font_t *font)
unsigned int i;
free (font->widths);
if (font->font_name)
free (font->font_name);
free (font->font_name);
free (font->ps_name);
free (font->subset_font_name);
_cairo_array_fini (&font->output);
@ -2742,20 +2739,14 @@ cairo_cff_font_destroy (cairo_cff_font_t *font)
}
free (font->fd_dict);
}
if (font->global_subs_used)
free (font->global_subs_used);
if (font->local_subs_used)
free (font->local_subs_used);
if (font->fd_subset_map)
free (font->fd_subset_map);
if (font->private_dict_offset)
free (font->private_dict_offset);
free (font->global_subs_used);
free (font->local_subs_used);
free (font->fd_subset_map);
free (font->private_dict_offset);
if (font->is_cid) {
if (font->fdselect)
free (font->fdselect);
if (font->fdselect_subset)
free (font->fdselect_subset);
free (font->fdselect);
free (font->fdselect_subset);
if (font->fd_private_dict) {
for (i = 0; i < font->num_fontdicts; i++) {
if (font->fd_private_dict[i])
@ -2768,23 +2759,18 @@ cairo_cff_font_destroy (cairo_cff_font_t *font)
cff_index_fini (&font->fd_local_sub_index[i]);
free (font->fd_local_sub_index);
}
if (font->fd_local_sub_bias)
free (font->fd_local_sub_bias);
free (font->fd_local_sub_bias);
if (font->fd_local_subs_used) {
for (i = 0; i < font->num_fontdicts; i++) {
if (font->fd_local_subs_used[i])
free (font->fd_local_subs_used[i]);
free (font->fd_local_subs_used[i]);
}
free (font->fd_local_subs_used);
}
if (font->fd_default_width)
free (font->fd_default_width);
if (font->fd_nominal_width)
free (font->fd_nominal_width);
free (font->fd_default_width);
free (font->fd_nominal_width);
}
if (font->data)
free (font->data);
free (font->data);
free (font);
}
@ -2855,8 +2841,7 @@ _cairo_cff_subset_init (cairo_cff_subset_t *cff_subset,
fail4:
free (cff_subset->widths);
fail3:
if (cff_subset->font_name)
free (cff_subset->font_name);
free (cff_subset->font_name);
fail2:
free (cff_subset->ps_name);
fail1:
@ -2869,8 +2854,7 @@ void
_cairo_cff_subset_fini (cairo_cff_subset_t *subset)
{
free (subset->ps_name);
if (subset->font_name)
free (subset->font_name);
free (subset->font_name);
free (subset->widths);
free (subset->data);
}
@ -2977,8 +2961,7 @@ fail2:
cff_index_fini (&index);
fail1:
if (data)
free (data);
free (data);
return is_cid;
}
@ -3066,8 +3049,7 @@ fail5:
fail4:
free (font->widths);
fail3:
if (font->font_name)
free (font->font_name);
free (font->font_name);
free (font->ps_name);
fail2:
free (font->subset_font_name);

View file

@ -1711,10 +1711,8 @@ _cairo_directfb_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph,
"%s( scaled_glyph=%p, scaled_font=%p ).\n",
__FUNCTION__, scaled_glyph, scaled_font);
if (scaled_glyph->surface_private != NULL) {
free (scaled_glyph->surface_private);
scaled_glyph->surface_private = NULL;
}
free (scaled_glyph->surface_private);
scaled_glyph->surface_private = NULL;
}
static cairo_int_status_t

View file

@ -431,10 +431,8 @@ _cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled)
{
assert (unscaled->face == NULL);
if (unscaled->filename) {
free (unscaled->filename);
unscaled->filename = NULL;
}
free (unscaled->filename);
unscaled->filename = NULL;
CAIRO_MUTEX_FINI (unscaled->mutex);
}

View file

@ -825,8 +825,7 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
data_start);
if (data_start_gles2)
free (data_start_gles2);
free (data_start_gles2);
/* If we just treated some rgb-only data as rgba, then we have to
* go back and fix up the alpha channel where we filled in this

View file

@ -517,8 +517,7 @@ _cairo_gstate_set_dash (cairo_gstate_t *gstate, const double *dash, int num_dash
unsigned int i;
double dash_total;
if (gstate->stroke_style.dash)
free (gstate->stroke_style.dash);
free (gstate->stroke_style.dash);
gstate->stroke_style.num_dashes = num_dashes;

View file

@ -207,8 +207,7 @@ slim_hidden_def (cairo_glyph_allocate);
void
cairo_glyph_free (cairo_glyph_t *glyphs)
{
if (glyphs)
free (glyphs);
free (glyphs);
}
slim_hidden_def (cairo_glyph_free);
@ -258,8 +257,7 @@ slim_hidden_def (cairo_text_cluster_allocate);
void
cairo_text_cluster_free (cairo_text_cluster_t *clusters)
{
if (clusters)
free (clusters);
free (clusters);
}
slim_hidden_def (cairo_text_cluster_free);

View file

@ -365,8 +365,7 @@ cairo_path_destroy (cairo_path_t *path)
if (path == NULL || path == &_cairo_path_nil)
return;
if (path->data)
free (path->data);
free (path->data);
free (path);
}

View file

@ -1021,12 +1021,9 @@ _cairo_pdf_smask_group_destroy (cairo_pdf_smask_group_t *group)
cairo_pattern_destroy (group->source);
if (group->mask)
cairo_pattern_destroy (group->mask);
if (group->utf8)
free (group->utf8);
if (group->glyphs)
free (group->glyphs);
if (group->clusters)
free (group->clusters);
free (group->utf8);
free (group->glyphs);
free (group->clusters);
if (group->scaled_font)
cairo_scaled_font_destroy (group->scaled_font);
free (group);
@ -1662,8 +1659,7 @@ _cairo_pdf_source_surface_entry_pluck (void *entry, void *closure)
cairo_hash_table_t *patterns = closure;
_cairo_hash_table_remove (patterns, &surface_entry->base);
if (surface_entry->unique_id)
free (surface_entry->unique_id);
free (surface_entry->unique_id);
free (surface_entry);
}
@ -3877,8 +3873,7 @@ _cairo_pdf_surface_emit_unicode_for_glyph (cairo_pdf_surface_t *surface,
}
_cairo_output_stream_printf (surface->output, ">");
if (utf16)
free (utf16);
free (utf16);
return CAIRO_STATUS_SUCCESS;
}

View file

@ -709,10 +709,8 @@ read_png (struct png_read_closure_t *png_closure)
}
BAIL:
if (row_pointers != NULL)
free (row_pointers);
if (data != NULL)
free (data);
free (row_pointers);
free (data);
if (png != NULL)
png_destroy_read_struct (&png, &info, NULL);
if (png_closure->png_data != NULL) {

View file

@ -1500,10 +1500,8 @@ _cairo_quartz_surface_finish (void *abstract_surface)
surface->imageSurfaceEquiv = NULL;
}
if (surface->imageData) {
free (surface->imageData);
surface->imageData = NULL;
}
free (surface->imageData);
surface->imageData = NULL;
return CAIRO_STATUS_SUCCESS;
}

View file

@ -198,8 +198,7 @@ _cairo_sub_font_glyph_create (unsigned long scaled_font_glyph_index,
static void
_cairo_sub_font_glyph_destroy (cairo_sub_font_glyph_t *sub_font_glyph)
{
if (sub_font_glyph->utf8 != NULL)
free (sub_font_glyph->utf8);
free (sub_font_glyph->utf8);
free (sub_font_glyph);
}
@ -1028,14 +1027,10 @@ _cairo_scaled_font_subsets_foreach_internal (cairo_scaled_font_subsets_t
collection.utf8 == NULL ||
collection.to_latin_char == NULL ||
collection.latin_to_subset_glyph_index == NULL)) {
if (collection.glyphs != NULL)
free (collection.glyphs);
if (collection.utf8 != NULL)
free (collection.utf8);
if (collection.to_latin_char != NULL)
free (collection.to_latin_char);
if (collection.latin_to_subset_glyph_index != NULL)
free (collection.latin_to_subset_glyph_index);
free (collection.glyphs);
free (collection.utf8);
free (collection.to_latin_char);
free (collection.latin_to_subset_glyph_index);
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
@ -1205,8 +1200,7 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
} else {
snprintf (buf, sizeof (buf), "g%d", i);
}
if (utf16)
free (utf16);
free (utf16);
subset->glyph_names[i] = strdup (buf);
if (unlikely (subset->glyph_names[i] == NULL)) {
@ -1234,8 +1228,7 @@ CLEANUP_HASH:
if (subset->glyph_names != NULL) {
for (i = 0; i < subset->num_glyphs; i++) {
if (subset->glyph_names[i] != NULL)
free (subset->glyph_names[i]);
free (subset->glyph_names[i]);
}
free (subset->glyph_names);

View file

@ -1159,10 +1159,8 @@ _cairo_scaled_font_reset_static_data (void)
status <= CAIRO_STATUS_LAST_STATUS;
status++)
{
if (_cairo_scaled_font_nil_objects[status] != NULL) {
free (_cairo_scaled_font_nil_objects[status]);
_cairo_scaled_font_nil_objects[status] = NULL;
}
free (_cairo_scaled_font_nil_objects[status]);
_cairo_scaled_font_nil_objects[status] = NULL;
}
CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex);

View file

@ -778,10 +778,8 @@ _emit_dash (cairo_script_surface_t *surface,
memcpy (surface->cr.current_style.dash, dash,
sizeof (double) * num_dashes);
} else {
if (surface->cr.current_style.dash != NULL) {
free (surface->cr.current_style.dash);
surface->cr.current_style.dash = NULL;
}
free (surface->cr.current_style.dash);
surface->cr.current_style.dash = NULL;
}
surface->cr.current_style.num_dashes = num_dashes;
@ -1989,10 +1987,9 @@ _cairo_script_surface_finish (void *abstract_surface)
_cairo_surface_wrapper_fini (&surface->wrapper);
if (surface->cr.current_style.dash != NULL) {
free (surface->cr.current_style.dash);
surface->cr.current_style.dash = NULL;
}
free (surface->cr.current_style.dash);
surface->cr.current_style.dash = NULL;
_cairo_pattern_fini (&surface->cr.current_source.base);
_cairo_path_fixed_fini (&surface->cr.current_path);
_cairo_surface_clipper_reset (&surface->clipper);
@ -3482,10 +3479,9 @@ _cairo_script_implicit_context_init (cairo_script_implicit_context_t *cr)
static void
_cairo_script_implicit_context_reset (cairo_script_implicit_context_t *cr)
{
if (cr->current_style.dash != NULL) {
free (cr->current_style.dash);
cr->current_style.dash = NULL;
}
free (cr->current_style.dash);
cr->current_style.dash = NULL;
_cairo_pattern_fini (&cr->current_source.base);
_cairo_path_fixed_fini (&cr->current_path);

View file

@ -86,10 +86,9 @@ _cairo_stroke_style_init_copy (cairo_stroke_style_t *style,
void
_cairo_stroke_style_fini (cairo_stroke_style_t *style)
{
if (style->dash) {
free (style->dash);
style->dash = NULL;
}
free (style->dash);
style->dash = NULL;
style->num_dashes = 0;
VG (VALGRIND_MAKE_MEM_NOACCESS (style, sizeof (cairo_stroke_style_t)));

View file

@ -1528,8 +1528,7 @@ _cairo_surface_fallback_composite_trapezoids (cairo_operator_t op,
traps, num_traps,
clip_region);
FAIL:
if (offset_traps != NULL)
free (offset_traps);
free (offset_traps);
if (fallback_region != NULL)
cairo_region_destroy (fallback_region);

View file

@ -1170,8 +1170,7 @@ cairo_surface_set_mime_data (cairo_surface_t *surface,
mime_data,
_cairo_mime_data_destroy);
if (unlikely (status)) {
if (mime_data != NULL)
free (mime_data);
free (mime_data);
return _cairo_surface_set_error (surface, status);
}

View file

@ -269,8 +269,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t *scaled_font_subset,
free (font->base.ps_name);
fail3:
free (font->parent_to_subset);
if (font->base.font_name)
free (font->base.font_name);
free (font->base.font_name);
fail2:
free (font->glyphs);
fail1:
@ -286,8 +285,7 @@ cairo_truetype_font_destroy (cairo_truetype_font_t *font)
_cairo_array_fini (&font->string_offsets);
free (font->base.widths);
free (font->base.ps_name);
if (font->base.font_name)
free (font->base.font_name);
free (font->base.font_name);
free (font->parent_to_subset);
free (font->glyphs);
_cairo_array_fini (&font->output);
@ -1201,8 +1199,7 @@ cairo_truetype_subset_init_internal (cairo_truetype_subset_t *truetype_subse
fail4:
free (truetype_subset->widths);
fail3:
if (truetype_subset->font_name)
free (truetype_subset->font_name);
free (truetype_subset->font_name);
fail2:
free (truetype_subset->ps_name);
fail1:
@ -1229,8 +1226,7 @@ void
_cairo_truetype_subset_fini (cairo_truetype_subset_t *subset)
{
free (subset->ps_name);
if (subset->font_name)
free (subset->font_name);
free (subset->font_name);
free (subset->widths);
free (subset->data);
free (subset->string_offsets);
@ -1493,11 +1489,9 @@ _cairo_truetype_read_font_name (cairo_scaled_font_t *scaled_font,
fail:
free (name);
if (ps_name != NULL)
free (ps_name);
free (ps_name);
if (font_name != NULL)
free (font_name);
free (font_name);
*ps_name_out = NULL;
*font_name_out = NULL;

View file

@ -1492,17 +1492,14 @@ _cairo_type1_font_subset_fini (cairo_type1_font_subset_t *font)
_cairo_array_fini (&font->glyph_names_array);
_cairo_array_fini (&font->glyphs_array);
if (font->subrs)
free (font->subrs);
free (font->subrs);
if (font->output != NULL)
status = _cairo_output_stream_destroy (font->output);
if (font->base.base_font)
free (font->base.base_font);
free (font->base.base_font);
if (font->subset_index_to_glyphs)
free (font->subset_index_to_glyphs);
free (font->subset_index_to_glyphs);
return status;
}

View file

@ -780,14 +780,11 @@ _cairo_win32_scaled_font_text_to_glyphs (void *abstract_font,
goto FAIL1;
while (TRUE) {
if (glyph_indices) {
free (glyph_indices);
glyph_indices = NULL;
}
if (dx) {
free (dx);
dx = NULL;
}
free (glyph_indices);
glyph_indices = NULL;
free (dx);
dx = NULL;
glyph_indices = _cairo_malloc_ab (buffer_size, sizeof (WCHAR));
dx = _cairo_malloc_ab (buffer_size, sizeof (int));
@ -840,10 +837,8 @@ _cairo_win32_scaled_font_text_to_glyphs (void *abstract_font,
}
FAIL2:
if (glyph_indices)
free (glyph_indices);
if (dx)
free (dx);
free (glyph_indices);
free (dx);
cairo_win32_scaled_font_done_font (&scaled_font->base);
@ -1624,10 +1619,8 @@ _cairo_win32_scaled_font_index_to_ucs4 (void *abstract_font,
}
exit2:
if (glyph_indices)
free (glyph_indices);
if (utf16)
free (utf16);
free (glyph_indices);
free (utf16);
free (glyph_set);
exit1:
cairo_win32_scaled_font_done_font (&scaled_font->base);

View file

@ -1363,8 +1363,7 @@ _cairo_win32_printing_surface_stroke (void *abstract_surface,
}
RestoreDC (surface->dc, -1);
DeleteObject (pen);
if (dash_array)
free (dash_array);
free (dash_array);
return status;
}

View file

@ -262,8 +262,7 @@ _cairo_xcb_connection_get_image (cairo_xcb_connection_t *connection,
if (error) {
free (error);
if (*reply)
free (*reply);
free (*reply);
*reply = NULL;
}

View file

@ -4056,8 +4056,7 @@ _cairo_xcb_font_destroy (cairo_xcb_font_t *font)
glyphset_info = &font->glyphset_info[i];
if (glyphset_info->pending_free_glyphs != NULL)
free (glyphset_info->pending_free_glyphs);
free (glyphset_info->pending_free_glyphs);
}
cairo_list_del (&font->link);

View file

@ -3941,8 +3941,7 @@ _cairo_xlib_surface_remove_scaled_font (cairo_xlib_display_t *display,
if (glyphset_info->glyphset)
XRenderFreeGlyphSet (display->display, glyphset_info->glyphset);
if (glyphset_info->pending_free_glyphs != NULL)
free (glyphset_info->pending_free_glyphs);
free (glyphset_info->pending_free_glyphs);
}
cairo_device_destroy (font_private->device);
@ -4013,8 +4012,7 @@ _cairo_xlib_surface_scaled_font_fini (cairo_scaled_font_t *scaled_font)
glyphset_info = &font_private->glyphset_info[i];
if (glyphset_info->pending_free_glyphs != NULL)
free (glyphset_info->pending_free_glyphs);
free (glyphset_info->pending_free_glyphs);
if (glyphset_info->glyphset) {
status = _cairo_xlib_display_queue_resource (display,

View file

@ -1496,8 +1496,7 @@ read_excludes (test_trace_t *test, const char *filename)
test->num_exclude_names++;
}
}
if (line != NULL)
free (line);
free (line);
fclose (file);
@ -1583,8 +1582,7 @@ test_fini (test_trace_t *test)
test_reset (test);
cairo_boilerplate_free_targets (test->targets);
if (test->exclude_names)
free (test->exclude_names);
free (test->exclude_names);
}
static cairo_bool_t

View file

@ -273,10 +273,8 @@ static char **process_file(const char *file_name, bfd_vma *addr, int naddr)
ret_buf = translate_addresses_buf(abfd, addr, naddr);
if (syms != NULL) {
free(syms);
syms = NULL;
}
free (syms);
syms = NULL;
bfd_close(abfd);
return ret_buf;

View file

@ -85,8 +85,7 @@ struct symbol {
static void
_symtab_fini (struct symtab *symtab)
{
if (symtab->syms != NULL)
free (symtab->syms);
free (symtab->syms);
if (symtab->bfd != NULL)
bfd_close (symtab->bfd);
}