remove superfluous free() checks

free() correctly handles NULL pointers, so we can omit explicit checks
for that condition.
This commit is contained in:
Clemens Ladisch 2006-02-27 09:58:32 +00:00
parent 45850439b3
commit 4433248bf3
33 changed files with 108 additions and 205 deletions

View file

@ -165,7 +165,6 @@ static void free_object(struct alisp_object * p)
switch (alisp_get_type(p)) {
case ALISP_OBJ_STRING:
case ALISP_OBJ_IDENTIFIER:
if (p->value.s)
free(p->value.s);
alisp_set_type(p, ALISP_OBJ_INTEGER);
break;
@ -523,7 +522,6 @@ static int init_lex(struct alisp_instance *instance)
static void done_lex(struct alisp_instance *instance)
{
if (instance->token_buffer)
free(instance->token_buffer);
}
@ -1184,7 +1182,6 @@ static struct alisp_object * F_concat(struct alisp_instance *instance, struct al
str1 = realloc(str, (str ? strlen(str) : 0) + strlen(p1->value.s) + 1);
if (str1 == NULL) {
nomem();
if (str)
free(str);
return NULL;
}
@ -2366,7 +2363,6 @@ static struct alisp_object * eval_func(struct alisp_instance *instance, struct a
}
_end:
if (eval_objs)
free(eval_objs);
return p4;

View file

@ -980,7 +980,6 @@ static int parse_value(snd_config_t **_n, snd_config_t *father, input_t *input,
if (err < 0)
return err;
}
if (n->u.string)
free(n->u.string);
n->u.string = s;
*_n = n;
@ -1056,7 +1055,6 @@ static int parse_array_def(snd_config_t *father, input_t *input, int idx, int sk
}
err = 0;
__end:
if (id)
free(id);
return err;
}
@ -1218,7 +1216,6 @@ static int parse_def(snd_config_t *father, input_t *input, int skip, int overrid
unget_char(c, input);
}
__end:
if (id)
free(id);
return err;
}
@ -1446,7 +1443,6 @@ int snd_config_substitute(snd_config_t *dst, snd_config_t *src)
if (err < 0)
return err;
}
if (dst->id)
free(dst->id);
dst->id = src->id;
dst->type = src->type;
@ -1528,7 +1524,6 @@ int snd_config_set_id(snd_config_t *config, const char *id)
new_id = strdup(id);
if (!new_id)
return -ENOMEM;
if (config->id)
free(config->id);
config->id = new_id;
return 0;
@ -1696,7 +1691,6 @@ int snd_config_delete(snd_config_t *config)
break;
}
case SND_CONFIG_TYPE_STRING:
if (config->u.string)
free(config->u.string);
break;
default:
@ -1704,7 +1698,6 @@ int snd_config_delete(snd_config_t *config)
}
if (config->father)
list_del(&config->list);
if (config->id)
free(config->id);
free(config);
return 0;
@ -2023,7 +2016,6 @@ int snd_config_set_string(snd_config_t *config, const char *value)
} else {
new_string = NULL;
}
if (config->u.string)
free(config->u.string);
config->u.string = new_string;
return 0;
@ -2091,7 +2083,6 @@ int snd_config_set_ascii(snd_config_t *config, const char *ascii)
char *ptr = strdup(ascii);
if (ptr == NULL)
return -ENOMEM;
if (config->u.string)
free(config->u.string);
config->u.string = ptr;
}
@ -2702,7 +2693,6 @@ static int snd_config_hooks_call(snd_config_t *root, snd_config_t *config, snd_c
if (err >= 0 && nroot)
err = snd_config_substitute(root, nroot);
}
if (buf)
free(buf);
if (err < 0)
return err;
@ -2844,10 +2834,9 @@ int snd_config_hook_load(snd_config_t *root, snd_config_t *config, snd_config_t
*dst = NULL;
err = 0;
_err:
for (idx = 0; idx < fi_count; idx++)
if (fi[idx].name)
free(fi[idx].name);
if (fi)
for (idx = 0; idx < fi_count; idx++)
free(fi[idx].name);
free(fi);
snd_config_delete(n);
return err;
@ -2905,7 +2894,6 @@ int snd_config_hook_load_for_all_cards(snd_config_t *root, snd_config_t *config,
__err:
if (private_data)
snd_config_delete(private_data);
if (fdriver)
free(fdriver);
if (err < 0)
return err;
@ -3108,7 +3096,6 @@ int snd_config_update_free(snd_config_update_t *update)
assert(update);
for (k = 0; k < update->count; k++)
free(update->finfo[k].name);
if (update->finfo)
free(update->finfo);
free(update);
return 0;
@ -3500,7 +3487,6 @@ static int _snd_config_evaluate(snd_config_t *src,
}
}
_errbuf:
if (buf)
free(buf);
if (err < 0)
return err;

View file

@ -295,7 +295,6 @@ int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
free(res);
}
__error:
if (def)
free(def);
return err;
}
@ -419,7 +418,6 @@ int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
tmp = realloc(res, len + len1 + 1);
if (tmp == NULL) {
free(ptr);
if (res)
free(res);
err = -ENOMEM;
goto __error;

View file

@ -94,7 +94,6 @@ int snd_ctl_close(snd_ctl_t *ctl)
snd_async_del_handler(h);
}
err = ctl->ops->close(ctl);
if (ctl->name)
free(ctl->name);
if (ctl->dl_handle)
snd_dlclose(ctl->dl_handle);
@ -925,7 +924,6 @@ const char *snd_ctl_event_type_name(snd_ctl_event_type_t type)
*/
int snd_ctl_elem_list_alloc_space(snd_ctl_elem_list_t *obj, unsigned int entries)
{
if (obj->pids)
free(obj->pids);
obj->pids = calloc(entries, sizeof(*obj->pids));
if (!obj->pids) {

View file

@ -555,7 +555,6 @@ int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *sockname
close(sock);
if (ctrl)
shmdt(ctrl);
if (shm)
free(shm);
return result;
}

View file

@ -606,7 +606,6 @@ int snd_hctl_load(snd_hctl_t *hctl)
}
err = snd_ctl_subscribe_events(hctl->ctl, 1);
_end:
if (list.pids)
free(list.pids);
return err;
}

View file

@ -207,7 +207,6 @@ int snd_hwdep_close(snd_hwdep_t *hwdep)
int err;
assert(hwdep);
err = hwdep->ops->close(hwdep);
if (hwdep->name)
free(hwdep->name);
free(hwdep);
return err;

View file

@ -382,11 +382,8 @@ int snd_instr_iwffff_close(snd_iwffff_handle_t *handle)
{
if (handle == NULL)
return -EINVAL;
if (handle->dat_filename)
free(handle->dat_filename);
if (handle->fff_filename)
free(handle->fff_filename);
if (handle->fff_data)
free(handle->fff_data);
free(handle);
return 0;
@ -396,7 +393,6 @@ static void free_wave(iwffff_wave_t *wave)
{
if (wave == NULL)
return;
if (wave->address.ptr != NULL)
free(wave->address.ptr);
free(wave);
}

View file

@ -607,10 +607,8 @@ int snd_mixer_close(snd_mixer_t *mixer)
}
assert(list_empty(&mixer->elems));
assert(mixer->count == 0);
if (mixer->pelems) {
free(mixer->pelems);
mixer->pelems = NULL;
}
while (!list_empty(&mixer->slaves)) {
int err;
snd_mixer_slave_t *s;

View file

@ -182,7 +182,6 @@ static void private_free(snd_mixer_class_t *class)
snd_hctl_close(priv->hctl);
} else if (priv->ctl)
snd_ctl_close(priv->ctl);
if (priv->device)
free(priv->device);
free(priv);
}

View file

@ -1388,7 +1388,6 @@ int snd_mixer_simple_none_register(snd_mixer_t *mixer,
snd_mixer_class_set_compare(class, snd_mixer_selem_compare);
err = snd_mixer_class_register(class, mixer);
if (err < 0) {
if (class)
free(class);
return err;
}

View file

@ -105,16 +105,13 @@ static int names_parse(snd_config_t *top, const char *iface, snd_devname_t **lis
}
last = dn;
} else {
if (comment != NULL)
free(comment);
}
}
return 0;
_err:
if (name)
free(name);
if (comment)
free(comment);
return err;
}
@ -189,9 +186,7 @@ void snd_names_list_free(snd_devname_t *list)
while (list != NULL) {
next = list->next;
if (list->name)
free(list->name);
if (list->comment)
free(list->comment);
free(list);
list = next;

View file

@ -2102,9 +2102,7 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
}
if (type_conf)
snd_config_delete(type_conf);
if (buf)
free(buf);
if (buf1)
free(buf1);
return err;
}
@ -2187,11 +2185,8 @@ int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
int snd_pcm_free(snd_pcm_t *pcm)
{
assert(pcm);
if (pcm->name)
free(pcm->name);
if (pcm->hw.link_dst)
free(pcm->hw.link_dst);
if (pcm->appl.link_dst)
free(pcm->appl.link_dst);
if (pcm->dl_handle)
snd_dlclose(pcm->dl_handle);

View file

@ -449,10 +449,8 @@ static int snd_pcm_adpcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
static int snd_pcm_adpcm_hw_free(snd_pcm_t *pcm)
{
snd_pcm_adpcm_t *adpcm = pcm->private_data;
if (adpcm->states) {
free(adpcm->states);
adpcm->states = 0;
}
adpcm->states = NULL;
return snd_pcm_hw_free(adpcm->plug.gen.slave);
}

View file

@ -639,7 +639,6 @@ static int snd_pcm_dmix_close(snd_pcm_t *pcm)
shm_sum_discard(dmix);
snd_pcm_direct_shm_discard(dmix);
snd_pcm_direct_semaphore_up(dmix, DIRECT_IPC_SEM_CLIENT);
if (dmix->bindings)
free(dmix->bindings);
pcm->private_data = NULL;
free(dmix);
@ -941,7 +940,6 @@ int snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name,
snd_pcm_direct_semaphore_up(dmix, DIRECT_IPC_SEM_CLIENT);
_err_nosem:
if (dmix) {
if (dmix->bindings)
free(dmix->bindings);
free(dmix);
}

View file

@ -466,7 +466,6 @@ static int snd_pcm_dshare_close(snd_pcm_t *pcm)
snd_pcm_direct_client_discard(dshare);
snd_pcm_direct_shm_discard(dshare);
snd_pcm_direct_semaphore_up(dshare, DIRECT_IPC_SEM_CLIENT);
if (dshare->bindings)
free(dshare->bindings);
pcm->private_data = NULL;
free(dshare);
@ -763,7 +762,6 @@ int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,
snd_pcm_direct_semaphore_up(dshare, DIRECT_IPC_SEM_CLIENT);
_err_nosem:
if (dshare) {
if (dshare->bindings)
free(dshare->bindings);
free(dshare);
}

View file

@ -362,7 +362,6 @@ static int snd_pcm_dsnoop_close(snd_pcm_t *pcm)
snd_pcm_direct_client_discard(dsnoop);
snd_pcm_direct_shm_discard(dsnoop);
snd_pcm_direct_semaphore_up(dsnoop, DIRECT_IPC_SEM_CLIENT);
if (dsnoop->bindings)
free(dsnoop->bindings);
pcm->private_data = NULL;
free(dsnoop);
@ -636,7 +635,6 @@ int snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name,
snd_pcm_direct_semaphore_up(dsnoop, DIRECT_IPC_SEM_CLIENT);
_err_nosem:
if (dsnoop) {
if (dsnoop->bindings)
free(dsnoop->bindings);
free(dsnoop);
}

View file

@ -263,13 +263,10 @@ static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm,
static int snd_pcm_file_hw_free(snd_pcm_t *pcm)
{
snd_pcm_file_t *file = pcm->private_data;
if (file->wbuf) {
free(file->wbuf);
if (file->wbuf_areas)
free(file->wbuf_areas);
file->wbuf = 0;
file->wbuf_areas = 0;
}
file->wbuf = NULL;
file->wbuf_areas = NULL;
return snd_pcm_hw_free(file->gen.slave);
}
@ -418,7 +415,6 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
err = snd_pcm_new(&pcm, SND_PCM_TYPE_FILE, name, slave->stream, slave->mode);
if (err < 0) {
if (fname)
free(file->fname);
free(file);
return err;

View file

@ -843,10 +843,8 @@ static int snd_pcm_hw_munmap_status(snd_pcm_t *pcm)
snd_pcm_hw_t *hw = pcm->private_data;
int err;
if (hw->sync_ptr_ioctl) {
if (hw->sync_ptr) {
free(hw->sync_ptr);
hw->sync_ptr = NULL;
}
} else {
if (munmap((void*)hw->mmap_status, page_align(sizeof(*hw->mmap_status))) < 0) {
err = -errno;
@ -862,10 +860,8 @@ static int snd_pcm_hw_munmap_control(snd_pcm_t *pcm)
snd_pcm_hw_t *hw = pcm->private_data;
int err;
if (hw->sync_ptr_ioctl) {
if (hw->sync_ptr) {
free(hw->sync_ptr);
hw->sync_ptr = NULL;
}
} else {
if (munmap(hw->mmap_control, page_align(sizeof(*hw->mmap_control))) < 0) {
err = -errno;

View file

@ -175,9 +175,7 @@ static int snd_pcm_ladspa_find_port_idx(unsigned int *res,
static void snd_pcm_ladspa_free_io(snd_pcm_ladspa_plugin_io_t *io)
{
if (io->controls)
free(io->controls);
if (io->controls_initialized)
free(io->controls_initialized);
}
@ -189,7 +187,6 @@ static void snd_pcm_ladspa_free_plugins(struct list_head *plugins)
snd_pcm_ladspa_free_io(&plugin->output);
if (plugin->dl_handle)
dlclose(plugin->dl_handle);
if (plugin->filename)
free(plugin->filename);
list_del(&plugin->list);
free(plugin);
@ -203,7 +200,6 @@ static void snd_pcm_ladspa_free(snd_pcm_ladspa_t *ladspa)
snd_pcm_ladspa_free_plugins(&ladspa->pplugins);
snd_pcm_ladspa_free_plugins(&ladspa->cplugins);
for (idx = 0; idx < 2; idx++) {
if (ladspa->zero[idx])
free(ladspa->zero[idx]);
ladspa->zero[idx] = NULL;
}
@ -317,9 +313,7 @@ static int snd_pcm_ladspa_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params
static void snd_pcm_ladspa_free_eps(snd_pcm_ladspa_eps_t *eps)
{
if (eps->channels.array)
free(eps->channels.array);
if (eps->ports.array)
free(eps->ports.array);
}
@ -340,13 +334,11 @@ static void snd_pcm_ladspa_free_instances(snd_pcm_t *pcm, snd_pcm_ladspa_t *lads
plugin->desc->cleanup(instance->handle);
if (instance->input.m_data) {
for (idx = 0; idx < instance->input.channels.size; idx++)
if (instance->input.m_data[idx])
free(instance->input.m_data[idx]);
free(instance->input.m_data);
}
if (instance->output.m_data) {
for (idx = 0; idx < instance->output.channels.size; idx++)
if (instance->output.m_data[idx])
free(instance->output.m_data[idx]);
free(instance->output.m_data);
}
@ -789,10 +781,8 @@ static int snd_pcm_ladspa_allocate_memory(snd_pcm_t *pcm, snd_pcm_ladspa_t *lads
for (idx = 0; idx < instance->output.channels.size; idx++) {
chn = instance->output.channels.array[idx];
if (instance->output.data[idx] == pchannels[chn]) {
if (instance->output.m_data[idx]) {
free(instance->output.m_data[idx]);
instance->output.m_data[idx] = NULL;
}
if (chn < ochannels) {
instance->output.data[idx] = NULL;
} else {

View file

@ -153,8 +153,7 @@ static int snd_pcm_meter_update_scope(snd_pcm_t *pcm)
static int snd_pcm_scope_remove(snd_pcm_scope_t *scope)
{
if (scope->name)
free((void *)scope->name);
free(scope->name);
scope->ops->close(scope);
list_del(&scope->list);
free(scope);
@ -480,12 +479,10 @@ static int snd_pcm_meter_hw_free(snd_pcm_t *pcm)
pthread_mutex_unlock(&meter->running_mutex);
err = pthread_join(meter->thread, 0);
assert(err == 0);
if (meter->buf) {
free(meter->buf);
free(meter->buf_areas);
meter->buf = 0;
meter->buf_areas = 0;
}
meter->buf = NULL;
meter->buf_areas = NULL;
return snd_pcm_hw_free(meter->gen.slave);
}
@ -1028,14 +1025,12 @@ static int s16_enable(snd_pcm_scope_t *scope)
}
s16->buf = malloc(meter->buf_size * 2 * spcm->channels);
if (!s16->buf) {
if (s16->adpcm_states)
free(s16->adpcm_states);
return -ENOMEM;
}
a = calloc(spcm->channels, sizeof(*a));
if (!a) {
free(s16->buf);
if (s16->adpcm_states)
free(s16->adpcm_states);
return -ENOMEM;
}
@ -1051,10 +1046,8 @@ static int s16_enable(snd_pcm_scope_t *scope)
static void s16_disable(snd_pcm_scope_t *scope)
{
snd_pcm_scope_s16_t *s16 = scope->private_data;
if (s16->adpcm_states) {
free(s16->adpcm_states);
s16->adpcm_states = NULL;
}
free(s16->buf);
s16->buf = NULL;
free(s16->buf_areas);

View file

@ -790,7 +790,7 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
multi->channels = calloc(channels_count, sizeof(*multi->channels));
if (!multi->channels) {
free(multi->slaves);
free(multi->channels);
free(multi);
return -ENOMEM;
}
for (i = 0; i < slaves_count; ++i) {
@ -1130,15 +1130,10 @@ _free:
}
free(slaves_conf);
}
if (slaves_pcm)
free(slaves_pcm);
if (slaves_channels)
free(slaves_channels);
if (channels_sidx)
free(channels_sidx);
if (channels_schannel)
free(channels_schannel);
if (slaves_id)
free(slaves_id);
return err;
}

View file

@ -62,7 +62,6 @@ static int snd_pcm_plug_close(snd_pcm_t *pcm)
{
snd_pcm_plug_t *plug = pcm->private_data;
int err, result = 0;
if (plug->ttable)
free(plug->ttable);
assert(plug->gen.slave == plug->req_slave);
if (plug->gen.close_slave) {

View file

@ -513,7 +513,6 @@ static int snd_pcm_route_close(snd_pcm_t *pcm)
if (params->dsts) {
for (dst_channel = 0; dst_channel < params->ndsts; ++dst_channel) {
if (params->dsts[dst_channel].srcs != NULL)
free(params->dsts[dst_channel].srcs);
}
free(params->dsts);

View file

@ -1689,9 +1689,7 @@ int _snd_pcm_share_open(snd_pcm_t **pcmp, const char *name,
speriod_time, sbuffer_time,
channels, channels_map, stream, mode);
_free:
if (channels_map)
free(channels_map);
if (sname)
free((char *)sname);
return err;
}

View file

@ -773,7 +773,6 @@ int snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
close(sock);
if (ctrl)
shmdt(ctrl);
if (shm)
free(shm);
return result;
}

View file

@ -342,7 +342,6 @@ int snd_rawmidi_close(snd_rawmidi_t *rawmidi)
int err;
assert(rawmidi);
err = rawmidi->ops->close(rawmidi);
if (rawmidi->name)
free(rawmidi->name);
if (rawmidi->dl_handle)
snd_dlclose(rawmidi->dl_handle);

View file

@ -316,11 +316,10 @@ int snd_rawmidi_hw_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
_nomem:
close(fd);
if (hw)
free(hw);
if (inputp && *inputp)
if (inputp)
free(*inputp);
if (outputp && *outputp)
if (outputp)
free(*outputp);
return -ENOMEM;
}

View file

@ -385,11 +385,10 @@ int snd_rawmidi_virtual_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
snd_seq_close(seq_handle);
if (virt->midi_event)
snd_midi_event_free(virt->midi_event);
if (virt)
free(virt);
if (inputp && *inputp)
if (inputp)
free(*inputp);
if (outputp && *outputp)
if (outputp)
free(*outputp);
return err;
}

View file

@ -1029,13 +1029,9 @@ int snd_seq_close(snd_seq_t *seq)
int err;
assert(seq);
err = seq->ops->close(seq);
if (seq->obuf)
free(seq->obuf);
if (seq->ibuf)
free(seq->ibuf);
if (seq->tmpbuf)
free(seq->tmpbuf);
if (seq->name)
free(seq->name);
free(seq);
return err;

View file

@ -167,7 +167,6 @@ int snd_midi_event_new(size_t bufsize, snd_midi_event_t **rdev)
void snd_midi_event_free(snd_midi_event_t *dev)
{
if (dev != NULL) {
if (dev->buf)
free(dev->buf);
free(dev);
}
@ -253,7 +252,6 @@ int snd_midi_event_resize_buffer(snd_midi_event_t *dev, size_t bufsize)
dev->buf = new_buf;
dev->bufsize = bufsize;
reset_encode(dev);
if (old_buf)
free(old_buf);
return 0;
}

View file

@ -243,7 +243,6 @@ int snd_timer_close(snd_timer_t *timer)
snd_async_del_handler(h);
}
err = timer->ops->close(timer);
if (timer->name)
free(timer->name);
free(timer);
return err;

View file

@ -197,7 +197,6 @@ int snd_timer_query_close(snd_timer_query_t *timer)
int err;
assert(timer);
err = timer->ops->close(timer);
if (timer->name)
free(timer->name);
free(timer);
return err;