mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-09 13:30:03 -05:00
remove superfluous free() checks
free() correctly handles NULL pointers, so we can omit explicit checks for that condition.
This commit is contained in:
parent
45850439b3
commit
4433248bf3
33 changed files with 108 additions and 205 deletions
|
|
@ -2102,10 +2102,8 @@ 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);
|
||||
free(buf);
|
||||
free(buf1);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -2187,12 +2185,9 @@ 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);
|
||||
free(pcm->name);
|
||||
free(pcm->hw.link_dst);
|
||||
free(pcm->appl.link_dst);
|
||||
if (pcm->dl_handle)
|
||||
snd_dlclose(pcm->dl_handle);
|
||||
free(pcm);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
free(adpcm->states);
|
||||
adpcm->states = NULL;
|
||||
return snd_pcm_hw_free(adpcm->plug.gen.slave);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -639,8 +639,7 @@ 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);
|
||||
free(dmix->bindings);
|
||||
pcm->private_data = NULL;
|
||||
free(dmix);
|
||||
return 0;
|
||||
|
|
@ -941,8 +940,7 @@ 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->bindings);
|
||||
free(dmix);
|
||||
}
|
||||
if (pcm)
|
||||
|
|
|
|||
|
|
@ -466,8 +466,7 @@ 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);
|
||||
free(dshare->bindings);
|
||||
pcm->private_data = NULL;
|
||||
free(dshare);
|
||||
return 0;
|
||||
|
|
@ -763,8 +762,7 @@ 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->bindings);
|
||||
free(dshare);
|
||||
}
|
||||
if (pcm)
|
||||
|
|
|
|||
|
|
@ -362,8 +362,7 @@ 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);
|
||||
free(dsnoop->bindings);
|
||||
pcm->private_data = NULL;
|
||||
free(dsnoop);
|
||||
return 0;
|
||||
|
|
@ -636,8 +635,7 @@ 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->bindings);
|
||||
free(dsnoop);
|
||||
}
|
||||
if (pcm)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
free(file->wbuf);
|
||||
free(file->wbuf_areas);
|
||||
file->wbuf = NULL;
|
||||
file->wbuf_areas = NULL;
|
||||
return snd_pcm_hw_free(file->gen.slave);
|
||||
}
|
||||
|
||||
|
|
@ -418,8 +415,7 @@ 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->fname);
|
||||
free(file);
|
||||
return err;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
free(hw->sync_ptr);
|
||||
hw->sync_ptr = NULL;
|
||||
} else {
|
||||
if (munmap(hw->mmap_control, page_align(sizeof(*hw->mmap_control))) < 0) {
|
||||
err = -errno;
|
||||
|
|
|
|||
|
|
@ -175,10 +175,8 @@ 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);
|
||||
free(io->controls);
|
||||
free(io->controls_initialized);
|
||||
}
|
||||
|
||||
static void snd_pcm_ladspa_free_plugins(struct list_head *plugins)
|
||||
|
|
@ -189,8 +187,7 @@ 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);
|
||||
free(plugin->filename);
|
||||
list_del(&plugin->list);
|
||||
free(plugin);
|
||||
}
|
||||
|
|
@ -203,8 +200,7 @@ 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]);
|
||||
free(ladspa->zero[idx]);
|
||||
ladspa->zero[idx] = NULL;
|
||||
}
|
||||
ladspa->allocated = 0;
|
||||
|
|
@ -317,10 +313,8 @@ 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);
|
||||
free(eps->channels.array);
|
||||
free(eps->ports.array);
|
||||
}
|
||||
|
||||
static void snd_pcm_ladspa_free_instances(snd_pcm_t *pcm, snd_pcm_ladspa_t *ladspa, int cleanup)
|
||||
|
|
@ -340,14 +334,12 @@ 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[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[idx]);
|
||||
free(instance->output.m_data);
|
||||
}
|
||||
list_del(&(instance->list));
|
||||
|
|
@ -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;
|
||||
}
|
||||
free(instance->output.m_data[idx]);
|
||||
instance->output.m_data[idx] = NULL;
|
||||
if (chn < ochannels) {
|
||||
instance->output.data[idx] = NULL;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
free(meter->buf);
|
||||
free(meter->buf_areas);
|
||||
meter->buf = NULL;
|
||||
meter->buf_areas = NULL;
|
||||
return snd_pcm_hw_free(meter->gen.slave);
|
||||
}
|
||||
|
||||
|
|
@ -1028,15 +1025,13 @@ 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);
|
||||
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);
|
||||
free(s16->adpcm_states);
|
||||
return -ENOMEM;
|
||||
}
|
||||
s16->buf_areas = a;
|
||||
|
|
@ -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->adpcm_states);
|
||||
s16->adpcm_states = NULL;
|
||||
free(s16->buf);
|
||||
s16->buf = NULL;
|
||||
free(s16->buf_areas);
|
||||
|
|
|
|||
|
|
@ -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,16 +1130,11 @@ _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);
|
||||
free(slaves_pcm);
|
||||
free(slaves_channels);
|
||||
free(channels_sidx);
|
||||
free(channels_schannel);
|
||||
free(slaves_id);
|
||||
return err;
|
||||
}
|
||||
#ifndef DOC_HIDDEN
|
||||
|
|
|
|||
|
|
@ -62,8 +62,7 @@ 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);
|
||||
free(plug->ttable);
|
||||
assert(plug->gen.slave == plug->req_slave);
|
||||
if (plug->gen.close_slave) {
|
||||
snd_pcm_unlink_hw_ptr(pcm, plug->req_slave);
|
||||
|
|
|
|||
|
|
@ -513,8 +513,7 @@ 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[dst_channel].srcs);
|
||||
}
|
||||
free(params->dsts);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1689,10 +1689,8 @@ 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);
|
||||
free(channels_map);
|
||||
free((char *)sname);
|
||||
return err;
|
||||
}
|
||||
#ifndef DOC_HIDDEN
|
||||
|
|
|
|||
|
|
@ -773,8 +773,7 @@ int snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
|
|||
close(sock);
|
||||
if (ctrl)
|
||||
shmdt(ctrl);
|
||||
if (shm)
|
||||
free(shm);
|
||||
free(shm);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue