free() can handle NULL just fine so skip the check

Fixes #117
This commit is contained in:
Wim Taymans 2018-12-19 17:47:25 +01:00
parent b6db6e2130
commit 0984096089
13 changed files with 63 additions and 99 deletions

View file

@ -36,7 +36,6 @@ struct peaks_data {
static void impl_peaks_free(struct resample *r) static void impl_peaks_free(struct resample *r)
{ {
if (r->data)
free(r->data); free(r->data);
r->data = NULL; r->data = NULL;
} }

View file

@ -440,7 +440,6 @@ static void node_proxy_destroy(void *data)
} }
if (n->info) if (n->info)
pw_node_info_free(n->info); pw_node_info_free(n->info);
if (n->media)
free(n->media); free(n->media);
if (n->session) { if (n->session) {
spa_list_remove(&n->session_link); spa_list_remove(&n->session_link);

View file

@ -625,7 +625,6 @@ static int negotiate_buffers(struct impl *impl)
spa_buffer_alloc_fill_info(&info, 0, NULL, blocks, datas, aligns); spa_buffer_alloc_fill_info(&info, 0, NULL, blocks, datas, aligns);
info.skel_size = SPA_ROUND_UP_N(info.skel_size, 16); info.skel_size = SPA_ROUND_UP_N(info.skel_size, 16);
if (impl->buffers)
free(impl->buffers); free(impl->buffers);
impl->buffers = calloc(buffers, sizeof(struct spa_buffer *) + info.skel_size); impl->buffers = calloc(buffers, sizeof(struct spa_buffer *) + info.skel_size);
if (impl->buffers == NULL) if (impl->buffers == NULL)
@ -1111,12 +1110,9 @@ static void cleanup(struct impl *impl)
pw_unload_spa_interface(impl->adapter); pw_unload_spa_interface(impl->adapter);
} }
if (impl->buffers)
free(impl->buffers); free(impl->buffers);
if (impl->mem) { if (impl->mem)
pw_memblock_free(impl->mem); pw_memblock_free(impl->mem);
impl->mem = NULL;
}
free(impl); free(impl);
} }

View file

@ -216,6 +216,7 @@ static void client_destroy(struct client *this)
if (this->sender) { if (this->sender) {
spa_list_remove(&this->link); spa_list_remove(&this->link);
free(this->sender); free(this->sender);
this->sender = NULL;
} }
} }

View file

@ -51,11 +51,19 @@ struct pw_device *pw_device_new(struct pw_core *core,
struct pw_device *this; struct pw_device *this;
this = calloc(1, sizeof(*this) + user_data_size); this = calloc(1, sizeof(*this) + user_data_size);
if (this == NULL)
return NULL;
if (properties == NULL)
properties = pw_properties_new(NULL, NULL);
if (properties == NULL)
goto no_mem;
this->core = core; this->core = core;
this->properties = properties; this->properties = properties;
this->info.name = strdup(name); this->info.name = strdup(name);
this->info.props = properties ? &properties->dict : NULL; this->info.props = &properties->dict;
spa_hook_list_init(&this->listener_list); spa_hook_list_init(&this->listener_list);
spa_list_init(&this->node_list); spa_list_init(&this->node_list);
@ -66,6 +74,10 @@ struct pw_device *pw_device_new(struct pw_core *core,
pw_log_debug("device %p: new %s", this, name); pw_log_debug("device %p: new %s", this, name);
return this; return this;
no_mem:
free(this);
return NULL;
} }
void pw_device_destroy(struct pw_device *device) void pw_device_destroy(struct pw_device *device)
@ -85,9 +97,7 @@ void pw_device_destroy(struct pw_device *device)
spa_hook_remove(&device->global_listener); spa_hook_remove(&device->global_listener);
pw_global_destroy(device->global); pw_global_destroy(device->global);
} }
if (device->info.name)
free((char *)device->info.name); free((char *)device->info.name);
if (device->properties)
pw_properties_free(device->properties); pw_properties_free(device->properties);
free(device); free(device);

View file

@ -73,7 +73,6 @@ void pw_factory_destroy(struct pw_factory *factory)
spa_hook_remove(&factory->global_listener); spa_hook_remove(&factory->global_listener);
pw_global_destroy(factory->global); pw_global_destroy(factory->global);
} }
if (factory->info.name)
free((char *)factory->info.name); free((char *)factory->info.name);
if (factory->properties) if (factory->properties)
pw_properties_free(factory->properties); pw_properties_free(factory->properties);

View file

@ -135,22 +135,18 @@ struct pw_core_info *pw_core_info_update(struct pw_core_info *info,
info->change_mask = update->change_mask; info->change_mask = update->change_mask;
if (update->change_mask & PW_CORE_CHANGE_MASK_USER_NAME) { if (update->change_mask & PW_CORE_CHANGE_MASK_USER_NAME) {
if (info->user_name)
free((void *) info->user_name); free((void *) info->user_name);
info->user_name = update->user_name ? strdup(update->user_name) : NULL; info->user_name = update->user_name ? strdup(update->user_name) : NULL;
} }
if (update->change_mask & PW_CORE_CHANGE_MASK_HOST_NAME) { if (update->change_mask & PW_CORE_CHANGE_MASK_HOST_NAME) {
if (info->host_name)
free((void *) info->host_name); free((void *) info->host_name);
info->host_name = update->host_name ? strdup(update->host_name) : NULL; info->host_name = update->host_name ? strdup(update->host_name) : NULL;
} }
if (update->change_mask & PW_CORE_CHANGE_MASK_VERSION) { if (update->change_mask & PW_CORE_CHANGE_MASK_VERSION) {
if (info->version)
free((void *) info->version); free((void *) info->version);
info->version = update->version ? strdup(update->version) : NULL; info->version = update->version ? strdup(update->version) : NULL;
} }
if (update->change_mask & PW_CORE_CHANGE_MASK_NAME) { if (update->change_mask & PW_CORE_CHANGE_MASK_NAME) {
if (info->name)
free((void *) info->name); free((void *) info->name);
info->name = update->name ? strdup(update->name) : NULL; info->name = update->name ? strdup(update->name) : NULL;
} }
@ -166,13 +162,9 @@ struct pw_core_info *pw_core_info_update(struct pw_core_info *info,
void pw_core_info_free(struct pw_core_info *info) void pw_core_info_free(struct pw_core_info *info)
{ {
if (info->user_name)
free((void *) info->user_name); free((void *) info->user_name);
if (info->host_name)
free((void *) info->host_name); free((void *) info->host_name);
if (info->version)
free((void *) info->version); free((void *) info->version);
if (info->name)
free((void *) info->name); free((void *) info->name);
if (info->props) if (info->props)
pw_spa_dict_destroy(info->props); pw_spa_dict_destroy(info->props);
@ -195,7 +187,6 @@ struct pw_node_info *pw_node_info_update(struct pw_node_info *info,
info->change_mask = update->change_mask; info->change_mask = update->change_mask;
if (update->change_mask & PW_NODE_CHANGE_MASK_NAME) { if (update->change_mask & PW_NODE_CHANGE_MASK_NAME) {
if (info->name)
free((void *) info->name); free((void *) info->name);
info->name = update->name ? strdup(update->name) : NULL; info->name = update->name ? strdup(update->name) : NULL;
} }
@ -210,7 +201,6 @@ struct pw_node_info *pw_node_info_update(struct pw_node_info *info,
if (update->change_mask & PW_NODE_CHANGE_MASK_STATE) { if (update->change_mask & PW_NODE_CHANGE_MASK_STATE) {
info->state = update->state; info->state = update->state;
if (info->error)
free((void *) info->error); free((void *) info->error);
info->error = update->error ? strdup(update->error) : NULL; info->error = update->error ? strdup(update->error) : NULL;
} }
@ -225,9 +215,7 @@ struct pw_node_info *pw_node_info_update(struct pw_node_info *info,
void pw_node_info_free(struct pw_node_info *info) void pw_node_info_free(struct pw_node_info *info)
{ {
if (info->name)
free((void *) info->name); free((void *) info->name);
if (info->error)
free((void *) info->error); free((void *) info->error);
if (info->props) if (info->props)
pw_spa_dict_destroy(info->props); pw_spa_dict_destroy(info->props);
@ -278,7 +266,6 @@ struct pw_factory_info *pw_factory_info_update(struct pw_factory_info *info,
return NULL; return NULL;
} }
info->id = update->id; info->id = update->id;
if (info->name)
free((void *) info->name); free((void *) info->name);
info->name = update->name ? strdup(update->name) : NULL; info->name = update->name ? strdup(update->name) : NULL;
info->type = update->type; info->type = update->type;
@ -295,7 +282,6 @@ struct pw_factory_info *pw_factory_info_update(struct pw_factory_info *info,
void pw_factory_info_free(struct pw_factory_info *info) void pw_factory_info_free(struct pw_factory_info *info)
{ {
if (info->name)
free((void *) info->name); free((void *) info->name);
if (info->props) if (info->props)
pw_spa_dict_destroy(info->props); pw_spa_dict_destroy(info->props);
@ -317,17 +303,14 @@ struct pw_module_info *pw_module_info_update(struct pw_module_info *info,
info->change_mask = update->change_mask; info->change_mask = update->change_mask;
if (update->change_mask & PW_MODULE_CHANGE_MASK_NAME) { if (update->change_mask & PW_MODULE_CHANGE_MASK_NAME) {
if (info->name)
free((void *) info->name); free((void *) info->name);
info->name = update->name ? strdup(update->name) : NULL; info->name = update->name ? strdup(update->name) : NULL;
} }
if (update->change_mask & PW_MODULE_CHANGE_MASK_FILENAME) { if (update->change_mask & PW_MODULE_CHANGE_MASK_FILENAME) {
if (info->filename)
free((void *) info->filename); free((void *) info->filename);
info->filename = update->filename ? strdup(update->filename) : NULL; info->filename = update->filename ? strdup(update->filename) : NULL;
} }
if (update->change_mask & PW_MODULE_CHANGE_MASK_ARGS) { if (update->change_mask & PW_MODULE_CHANGE_MASK_ARGS) {
if (info->args)
free((void *) info->args); free((void *) info->args);
info->args = update->args ? strdup(update->args) : NULL; info->args = update->args ? strdup(update->args) : NULL;
} }
@ -341,11 +324,8 @@ struct pw_module_info *pw_module_info_update(struct pw_module_info *info,
void pw_module_info_free(struct pw_module_info *info) void pw_module_info_free(struct pw_module_info *info)
{ {
if (info->name)
free((void *) info->name); free((void *) info->name);
if (info->filename)
free((void *) info->filename); free((void *) info->filename);
if (info->args)
free((void *) info->args); free((void *) info->args);
if (info->props) if (info->props)
pw_spa_dict_destroy(info->props); pw_spa_dict_destroy(info->props);
@ -365,7 +345,6 @@ struct pw_device_info *pw_device_info_update(struct pw_device_info *info,
return NULL; return NULL;
} }
info->id = update->id; info->id = update->id;
if (info->name)
free((void *) info->name); free((void *) info->name);
info->name = update->name ? strdup(update->name) : NULL; info->name = update->name ? strdup(update->name) : NULL;
info->change_mask = update->change_mask; info->change_mask = update->change_mask;
@ -380,7 +359,6 @@ struct pw_device_info *pw_device_info_update(struct pw_device_info *info,
void pw_device_info_free(struct pw_device_info *info) void pw_device_info_free(struct pw_device_info *info)
{ {
if (info->name)
free((void *) info->name); free((void *) info->name);
if (info->props) if (info->props)
pw_spa_dict_destroy(info->props); pw_spa_dict_destroy(info->props);
@ -440,12 +418,10 @@ struct pw_link_info *pw_link_info_update(struct pw_link_info *info,
} }
if (update->change_mask & PW_LINK_CHANGE_MASK_STATE) { if (update->change_mask & PW_LINK_CHANGE_MASK_STATE) {
info->state = update->state; info->state = update->state;
if (info->error)
free((void *) info->error); free((void *) info->error);
info->error = update->error ? strdup(update->error) : NULL; info->error = update->error ? strdup(update->error) : NULL;
} }
if (update->change_mask & PW_LINK_CHANGE_MASK_FORMAT) { if (update->change_mask & PW_LINK_CHANGE_MASK_FORMAT) {
if (info->format)
free(info->format); free(info->format);
info->format = pw_spa_pod_copy(update->format); info->format = pw_spa_pod_copy(update->format);
} }
@ -459,9 +435,7 @@ struct pw_link_info *pw_link_info_update(struct pw_link_info *info,
void pw_link_info_free(struct pw_link_info *info) void pw_link_info_free(struct pw_link_info *info)
{ {
if (info->error)
free((void *) info->error); free((void *) info->error);
if (info->format)
free(info->format); free(info->format);
if (info->props) if (info->props)
pw_spa_dict_destroy(info->props); pw_spa_dict_destroy(info->props);

View file

@ -110,7 +110,6 @@ static void pw_link_update_state(struct pw_link *link, enum pw_link_state state,
} }
link->info.state = state; link->info.state = state;
if (link->info.error)
free((char*)link->info.error); free((char*)link->info.error);
link->info.error = error; link->info.error = error;
@ -312,7 +311,6 @@ static int do_negotiate(struct pw_link *this, uint32_t in_state, uint32_t out_st
} }
} }
if (this->info.format)
free(this->info.format); free(this->info.format);
this->info.format = format; this->info.format = format;
@ -332,7 +330,6 @@ static int do_negotiate(struct pw_link *this, uint32_t in_state, uint32_t out_st
error: error:
pw_link_update_state(this, PW_LINK_STATE_ERROR, error); pw_link_update_state(this, PW_LINK_STATE_ERROR, error);
if (format)
free(format); free(format);
return res; return res;
} }
@ -1515,9 +1512,7 @@ void pw_link_destroy(struct pw_link *link)
if (link->properties) if (link->properties)
pw_properties_free(link->properties); pw_properties_free(link->properties);
if (link->info.format)
free(link->info.format); free(link->info.format);
free(impl); free(impl);
} }

View file

@ -303,11 +303,8 @@ void pw_module_destroy(struct pw_module *module)
pw_global_destroy(module->global); pw_global_destroy(module->global);
} }
if (module->info.name)
free((char *) module->info.name); free((char *) module->info.name);
if (module->info.filename)
free((char *) module->info.filename); free((char *) module->info.filename);
if (module->info.args)
free((char *) module->info.args); free((char *) module->info.args);
pw_properties_free(module->properties); pw_properties_free(module->properties);

View file

@ -175,7 +175,6 @@ static void node_update_state(struct pw_node *node, enum pw_node_state state, ch
pw_node_state_as_string(old), pw_node_state_as_string(state)); pw_node_state_as_string(old), pw_node_state_as_string(state));
} }
if (node->info.error)
free((char*)node->info.error); free((char*)node->info.error);
node->info.error = error; node->info.error = error;
node->info.state = state; node->info.state = state;

View file

@ -140,7 +140,6 @@ pw_remote_update_state(struct pw_remote *remote, enum pw_remote_state state, con
enum pw_remote_state old = remote->state; enum pw_remote_state old = remote->state;
if (old != state) { if (old != state) {
if (remote->error)
free(remote->error); free(remote->error);
if (fmt) { if (fmt) {
@ -318,7 +317,6 @@ void pw_remote_destroy(struct pw_remote *remote)
pw_map_clear(&remote->objects); pw_map_clear(&remote->objects);
pw_log_debug("remote %p: free", remote); pw_log_debug("remote %p: free", remote);
if (remote->properties)
pw_properties_free(remote->properties); pw_properties_free(remote->properties);
free(remote->error); free(remote->error);
free(impl); free(impl);

View file

@ -212,7 +212,6 @@ static bool stream_set_state(struct pw_stream *stream, enum pw_stream_state stat
enum pw_stream_state old = stream->state; enum pw_stream_state old = stream->state;
bool res = old != state; bool res = old != state;
if (res) { if (res) {
if (stream->error)
free(stream->error); free(stream->error);
stream->error = error ? strdup(error) : NULL; stream->error = error ? strdup(error) : NULL;
@ -995,12 +994,10 @@ void pw_stream_destroy(struct pw_stream *stream)
clear_params(stream, PARAM_TYPE_INIT | PARAM_TYPE_OTHER | PARAM_TYPE_FORMAT); clear_params(stream, PARAM_TYPE_INIT | PARAM_TYPE_OTHER | PARAM_TYPE_FORMAT);
pw_array_clear(&impl->params); pw_array_clear(&impl->params);
if (stream->error)
free(stream->error); free(stream->error);
pw_properties_free(stream->properties); pw_properties_free(stream->properties);
if (stream->name)
free(stream->name); free(stream->name);
if (impl->free_data) if (impl->free_data)