remove useless if-before-free tests

In case you're wondering about whether this change is safe from a
portability standpoint, fear not.  This has been beaten to death
in other forums.  Here are a few threads:

  http://thread.gmane.org/gmane.comp.version-control.git/74187
  http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/12712
  http://thread.gmane.org/gmane.emacs.devel/98144
  http://thread.gmane.org/gmane.comp.lib.glibc.alpha/13092

There has been debate about whether it's a good idea from a
performance standpoint, too, but imho you'll have a hard time
finding an instance where this sort of change induces a
measurable performance penalty.  If you do, please let me know.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
bitmap-optimize
Jim Meyering 2009-02-23 18:07:50 +01:00 committed by Theodore Ts'o
parent a6d4aa1474
commit 45e338f533
31 changed files with 64 additions and 140 deletions

View File

@ -275,8 +275,7 @@ void do_htree_dump(int argc, char *argv[])
rootnode->indirect_levels);
errout:
if (buf)
free(buf);
free(buf);
close_pager(pager);
}

View File

@ -161,8 +161,7 @@ void do_icheck(int argc, char **argv)
error_out:
free(bw.barray);
if (block_buf)
free(block_buf);
free(block_buf);
if (scan)
ext2fs_close_inode_scan(scan);
return;

View File

@ -66,7 +66,7 @@ int argv_parse(char *in_buf, int *ret_argc, char ***ret_argv)
new_argv = realloc(argv,
(max_argc+1)*sizeof(char *));
if (!new_argv) {
if (argv) free(argv);
free(argv);
free(buf);
return -1;
}
@ -126,8 +126,7 @@ int argv_parse(char *in_buf, int *ret_argc, char ***ret_argv)
void argv_free(char **argv)
{
if (*argv)
free(*argv);
free(*argv);
free(argv);
}

View File

@ -326,8 +326,7 @@ extern struct dir_info_iter *e2fsck_dir_info_iter_begin(e2fsck_t ctx)
extern void e2fsck_dir_info_iter_end(e2fsck_t ctx EXT2FS_ATTR((unused)),
struct dir_info_iter *iter)
{
if (iter->tdb_iter.dptr)
free(iter->tdb_iter.dptr);
free(iter->tdb_iter.dptr);
ext2fs_free_mem(&iter);
}

View File

@ -603,8 +603,7 @@ void profile_free_file(prf_file_t prf)
{
if (prf->root)
profile_free_node(prf->root);
if (prf->filespec)
free(prf->filespec);
free(prf->filespec);
free(prf);
}
@ -1049,10 +1048,8 @@ void profile_free_node(struct profile_node *node)
if (node->magic != PROF_MAGIC_NODE)
return;
if (node->name)
free(node->name);
if (node->value)
free(node->value);
free(node->name);
free(node->value);
for (child=node->first_child; child; child = next) {
next = child->next;

View File

@ -247,10 +247,8 @@ static errcode_t alloc_size_dir(ext2_filsys fs, struct out_dir *outdir,
static void free_out_dir(struct out_dir *outdir)
{
if (outdir->buf)
free(outdir->buf);
if (outdir->hashes)
free(outdir->hashes);
free(outdir->buf);
free(outdir->hashes);
outdir->max = 0;
outdir->num =0;
}
@ -782,10 +780,8 @@ resort:
goto errout;
errout:
if (dir_buf)
free(dir_buf);
if (fd.harray)
free(fd.harray);
free(dir_buf);
free(fd.harray);
free_out_dir(&outdir);
return retval;

View File

@ -197,8 +197,7 @@ set_binding_values (const char *domainname,
if (__builtin_expect (result != NULL, 1))
{
if (binding->codeset != NULL)
free (binding->codeset);
free (binding->codeset);
binding->codeset = result;
binding->codeset_cntr++;

View File

@ -1372,8 +1372,7 @@ _nl_load_domain (struct loaded_l10nfile *domain_file,
/* This is an invalid revision. */
invalid:
/* This is an invalid .mo file. */
if (domain->malloced)
free (domain->malloced);
free (domain->malloced);
#ifdef HAVE_MMAP
if (use_mmap)
munmap ((void *) data, size);
@ -1405,8 +1404,7 @@ _nl_unload_domain (struct loaded_domain *domain)
_nl_free_domain_conv (domain);
if (domain->malloced)
free (domain->malloced);
free (domain->malloced);
# ifdef _POSIX_MAPPED_FILES
if (domain->use_mmap)

View File

@ -199,8 +199,7 @@ get_charset_aliases ()
}
}
if (file_name != NULL)
free (file_name);
free (file_name);
#else

View File

@ -524,10 +524,8 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
return 0;
error:
if (a->arg)
free (a->arg);
if (d->dir)
free (d->dir);
free (a->arg);
free (d->dir);
return -1;
}

View File

@ -801,8 +801,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
{
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
free (buf_malloced);
CLEANUP ();
errno = EINVAL;
return NULL;
@ -860,8 +859,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
result = memory;
}
if (buf_malloced != NULL)
free (buf_malloced);
free (buf_malloced);
CLEANUP ();
*lengthp = length;
return result;
@ -869,8 +867,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
out_of_memory:
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
free (buf_malloced);
out_of_memory_1:
CLEANUP ();
errno = ENOMEM;

View File

@ -146,8 +146,7 @@ void blkid_put_cache(blkid_cache cache)
}
blkid_free_tag(tag);
}
if (cache->bic_filename)
free(cache->bic_filename);
free(cache->bic_filename);
free(cache);
}

View File

@ -45,8 +45,7 @@ void blkid_free_dev(blkid_dev dev)
bit_tags);
blkid_free_tag(tag);
}
if (dev->bid_name)
free(dev->bid_name);
free(dev->bid_name);
free(dev);
}
@ -137,18 +136,14 @@ extern int blkid_dev_set_search(blkid_dev_iterate iter,
new_type = malloc(strlen(search_type)+1);
new_value = malloc(strlen(search_value)+1);
if (!new_type || !new_value) {
if (new_type)
free(new_type);
if (new_value)
free(new_value);
free(new_type);
free(new_value);
return -1;
}
strcpy(new_type, search_type);
strcpy(new_value, search_value);
if (iter->search_type)
free(iter->search_type);
if (iter->search_value)
free(iter->search_value);
free(iter->search_type);
free(iter->search_value);
iter->search_type = new_type;
iter->search_value = new_value;
return 0;

View File

@ -222,8 +222,7 @@ int main(int argc, char** argv)
}
printf("Looking for device 0x%04llx\n", (long long)devno);
devname = blkid_devno_to_devname(devno);
if (devname)
free(devname);
free(devname);
return 0;
}
#endif

View File

@ -1625,10 +1625,8 @@ found_type:
dev->bid_name, (long long)st.st_rdev, type));
}
if (probe.sbbuf)
free(probe.sbbuf);
if (probe.buf)
free(probe.buf);
free(probe.sbbuf);
free(probe.buf);
if (probe.fd >= 0)
close(probe.fd);

View File

@ -97,10 +97,8 @@ char *blkid_get_devname(blkid_cache cache, const char *token,
ret = blkid_strdup(blkid_dev_devname(dev));
out:
if (t)
free(t);
if (v)
free(v);
free(t);
free(v);
if (!cache) {
blkid_put_cache(c);
}

View File

@ -153,8 +153,7 @@ int blkid_flush_cache(blkid_cache cache)
}
errout:
if (tmp)
free(tmp);
free(tmp);
return ret;
}

View File

@ -54,10 +54,8 @@ void blkid_free_tag(blkid_tag tag)
list_del(&tag->bit_tags); /* list of tags for this device */
list_del(&tag->bit_names); /* list of tags with this type */
if (tag->bit_name)
free(tag->bit_name);
if (tag->bit_val)
free(tag->bit_val);
free(tag->bit_name);
free(tag->bit_val);
free(tag);
}
@ -206,8 +204,7 @@ int blkid_set_tag(blkid_dev dev, const char *name,
errout:
if (t)
blkid_free_tag(t);
else if (val)
free(val);
else free(val);
if (head)
blkid_free_tag(head);
return -BLKID_ERR_MEM;

View File

@ -278,8 +278,7 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
if(!HW_OK())
{
_dio_error = ERR_HARDWARE;
if (part)
free(part);
free(part);
return EFAULT;
}
@ -298,8 +297,7 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
if(!HW_OK())
{
_dio_error = ERR_HARDWARE;
if (part)
free(part);
free(part);
return EFAULT;
}
@ -310,8 +308,7 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
{
_dio_error = part->pno == 0xFE ? ERR_EMPTYPART :
part->pno == 0xFD ? ERR_LINUXSWAP : ERR_NOTEXT2FS;
if (part)
free(part);
free(part);
return ENODEV;
}
@ -352,10 +349,8 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
static errcode_t dos_close(io_channel channel)
{
if (channel->name)
free(channel->name);
if (channel)
free(channel);
free(channel->name);
free(channel);
return 0;
}

View File

@ -1007,8 +1007,7 @@ static errcode_t extent_node_split(ext2_extent_handle_t handle)
done:
if (newpath)
ext2fs_free_mem(&newpath);
if (block_buf)
free(block_buf);
free(block_buf);
return retval;
}

View File

@ -437,8 +437,7 @@ ipg_retry:
*ret_fs = fs;
return 0;
cleanup:
if (buf)
free(buf);
free(buf);
ext2fs_free(fs);
return retval;
}

View File

@ -1191,11 +1191,7 @@ nt_open(const char *name, int flags, io_channel *channel)
if (NULL != io)
{
if(NULL != io->name)
{
free(io->name);
}
free(io->name);
free(io);
}
@ -1207,11 +1203,7 @@ nt_open(const char *name, int flags, io_channel *channel)
_CloseDisk(NtData->Handle);
}
if(NULL != NtData->Buffer)
{
free(NtData->Buffer);
}
free(NtData->Buffer);
free(NtData);
}
}
@ -1245,12 +1237,7 @@ nt_close(io_channel channel)
return 0;
}
if(NULL != channel->name)
{
free(channel->name);
}
free(channel->name);
free(channel);
if (NULL != NtData)
@ -1262,11 +1249,7 @@ nt_close(io_channel channel)
_CloseDisk(NtData->Handle);
}
if(NULL != NtData->Buffer)
{
free(NtData->Buffer);
}
free(NtData->Buffer);
free(NtData);
}

View File

@ -221,8 +221,7 @@ int ss_execute_line (sci_idx, line_ptr)
/* parse it */
argv = ss_parse(sci_idx, line_ptr, &argc);
if (argc == 0) {
if (argv)
free(argv);
free(argv);
return 0;
}

View File

@ -1237,8 +1237,7 @@ int main (int argc, char ** argv)
close (dev);
if (out != stdout)
fclose (out);
if (t_patts)
free(t_patts);
free(t_patts);
return 0;
}

View File

@ -420,10 +420,8 @@ int main(int argc, char **argv)
}
exit:
if (search_type)
free(search_type);
if (search_value)
free(search_value);
free(search_type);
free(search_value);
blkid_put_cache(cache);
return err;
}

View File

@ -274,8 +274,7 @@ static int parse_fstab_line(char *line, struct fs_info *fs)
fs->flags = 0;
fs->next = NULL;
if (dev)
free(dev);
free(dev);
return 0;
}

View File

@ -233,12 +233,9 @@ static void parse_escape(char *word)
static void free_instance(struct fsck_instance *i)
{
if (i->prog)
free(i->prog);
if (i->device)
free(i->device);
if (i->base_device)
free(i->base_device);
free(i->prog);
free(i->device);
free(i->base_device);
free(i);
return;
}
@ -310,8 +307,7 @@ static int parse_fstab_line(char *line, struct fs_info **ret_fs)
fs = create_fs_device(device, mntpnt, type ? type : "auto", opts,
freq ? atoi(freq) : -1,
passno ? atoi(passno) : -1);
if (dev)
free(dev);
free(dev);
if (!fs)
return -1;

View File

@ -1024,8 +1024,7 @@ static char **parse_fs_type(const char *fs_type,
}
}
free(parse_str);
if (profile_type)
free(profile_type);
free(profile_type);
if (is_hurd)
push_string(&list, "hurd");
return (list.list);
@ -1523,16 +1522,14 @@ got_size:
"features", "", &tmp);
if (tmp && *tmp)
edit_feature(tmp, &fs_param.s_feature_compat);
if (tmp)
free(tmp);
free(tmp);
}
tmp = get_string_from_profile(fs_types, "default_features",
"");
}
edit_feature(fs_features ? fs_features : tmp,
&fs_param.s_feature_compat);
if (tmp)
free(tmp);
free(tmp);
if (fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
fs_types[0] = strdup("journal");
@ -1646,8 +1643,7 @@ got_size:
profile_get_string(profile, "fs_types", *cpp, "options", "", &tmp);
if (tmp && *tmp)
parse_extended_opts(&fs_param, tmp);
if (tmp)
free(tmp);
free(tmp);
}
if (extended_opts)

View File

@ -529,8 +529,7 @@ static void add_journal(ext2_filsys fs)
return;
err:
if (journal_device)
free(journal_device);
free(journal_device);
exit(1);
}

View File

@ -1396,8 +1396,7 @@ errout:
ext2fs_close_inode_scan(scan);
if (block_buf)
ext2fs_free_mem(&block_buf);
if (inode)
free(inode);
free(inode);
return retval;
}

View File

@ -54,10 +54,8 @@ static int add_subst(char *name, char *value)
return 0;
fail:
if (ent) {
if (ent->name)
free(ent->name);
if (ent->value)
free(ent->value);
free(ent->name);
free(ent->value);
free(ent);
}
return retval;