Fix some leaks in error cases

This commit is contained in:
Wim Taymans 2020-05-20 14:05:42 +02:00
parent 8669fd03a6
commit c2028a1695
9 changed files with 43 additions and 22 deletions

View file

@ -442,10 +442,6 @@ static struct endpoint *create_endpoint(struct node *node, struct endpoint *moni
return NULL; return NULL;
} }
props = pw_properties_new(NULL, NULL);
if (props == NULL)
return NULL;
if (strstr(media_class, "Source") != NULL) { if (strstr(media_class, "Source") != NULL) {
direction = PW_DIRECTION_OUTPUT; direction = PW_DIRECTION_OUTPUT;
} else if (strstr(media_class, "Sink") != NULL) { } else if (strstr(media_class, "Sink") != NULL) {
@ -455,6 +451,10 @@ static struct endpoint *create_endpoint(struct node *node, struct endpoint *moni
return NULL; return NULL;
} }
props = pw_properties_new(NULL, NULL);
if (props == NULL)
return NULL;
if (monitor != NULL) { if (monitor != NULL) {
pw_properties_set(props, PW_KEY_MEDIA_CLASS, "Audio/Source"); pw_properties_set(props, PW_KEY_MEDIA_CLASS, "Audio/Source");
direction = PW_DIRECTION_OUTPUT; direction = PW_DIRECTION_OUTPUT;

View file

@ -437,10 +437,6 @@ static struct endpoint *create_endpoint(struct node *node, struct endpoint *moni
return NULL; return NULL;
} }
props = pw_properties_new(NULL, NULL);
if (props == NULL)
return NULL;
if (strstr(media_class, "Source") != NULL) { if (strstr(media_class, "Source") != NULL) {
direction = PW_DIRECTION_OUTPUT; direction = PW_DIRECTION_OUTPUT;
} else if (strstr(media_class, "Sink") != NULL) { } else if (strstr(media_class, "Sink") != NULL) {
@ -450,6 +446,10 @@ static struct endpoint *create_endpoint(struct node *node, struct endpoint *moni
return NULL; return NULL;
} }
props = pw_properties_new(NULL, NULL);
if (props == NULL)
return NULL;
if (monitor != NULL) { if (monitor != NULL) {
pw_properties_set(props, PW_KEY_MEDIA_CLASS, "Audio/Source"); pw_properties_set(props, PW_KEY_MEDIA_CLASS, "Audio/Source");
direction = PW_DIRECTION_OUTPUT; direction = PW_DIRECTION_OUTPUT;

View file

@ -392,10 +392,6 @@ static struct endpoint *create_endpoint(struct node *node)
return NULL; return NULL;
} }
props = pw_properties_new(NULL, NULL);
if (props == NULL)
return NULL;
if (strstr(media_class, "Source") != NULL) { if (strstr(media_class, "Source") != NULL) {
direction = PW_DIRECTION_OUTPUT; direction = PW_DIRECTION_OUTPUT;
} else if (strstr(media_class, "Sink") != NULL) { } else if (strstr(media_class, "Sink") != NULL) {
@ -405,6 +401,10 @@ static struct endpoint *create_endpoint(struct node *node)
return NULL; return NULL;
} }
props = pw_properties_new(NULL, NULL);
if (props == NULL)
return NULL;
pw_properties_set(props, PW_KEY_MEDIA_CLASS, media_class); pw_properties_set(props, PW_KEY_MEDIA_CLASS, media_class);
if ((str = pw_properties_get(pr, PW_KEY_PRIORITY_SESSION)) != NULL) if ((str = pw_properties_get(pr, PW_KEY_PRIORITY_SESSION)) != NULL)

View file

@ -210,8 +210,10 @@ pw_client_node0_transport_new(struct pw_context *context,
PW_MEMBLOCK_FLAG_MAP | PW_MEMBLOCK_FLAG_MAP |
PW_MEMBLOCK_FLAG_SEAL, PW_MEMBLOCK_FLAG_SEAL,
SPA_DATA_MemFd, area_get_size(&area)); SPA_DATA_MemFd, area_get_size(&area));
if (impl->mem == NULL) if (impl->mem == NULL) {
free(impl);
return NULL; return NULL;
}
memcpy(impl->mem->map->ptr, &area, sizeof(struct pw_client_node0_area)); memcpy(impl->mem->map->ptr, &area, sizeof(struct pw_client_node0_area));
transport_setup_area(impl->mem->map->ptr, trans); transport_setup_area(impl->mem->map->ptr, trans);

View file

@ -95,6 +95,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
props, props,
sizeof(struct device_data)); sizeof(struct device_data));
if (device == NULL) { if (device == NULL) {
props = NULL;
res = -errno; res = -errno;
goto error_exit_cleanup; goto error_exit_cleanup;
} }
@ -119,5 +120,7 @@ error_arguments:
error_exit_cleanup: error_exit_cleanup:
if (argv) if (argv)
pw_free_strv(argv); pw_free_strv(argv);
if (props)
pw_properties_free(props);
return res; return res;
} }

View file

@ -1031,11 +1031,14 @@ pw_filter_new_simple(struct pw_loop *loop,
return NULL; return NULL;
context = pw_context_new(loop, NULL, 0); context = pw_context_new(loop, NULL, 0);
if (context == NULL) if (context == NULL) {
return NULL; res = -errno;
goto error_cleanup;
}
impl = filter_new(context, name, props, props); impl = filter_new(context, name, props, props);
if (impl == NULL) { if (impl == NULL) {
props = NULL;
res = -errno; res = -errno;
goto error_cleanup; goto error_cleanup;
} }
@ -1048,7 +1051,10 @@ pw_filter_new_simple(struct pw_loop *loop,
return this; return this;
error_cleanup: error_cleanup:
pw_context_destroy(context); if (context)
pw_context_destroy(context);
if (props)
pw_properties_free(props);
errno = -res; errno = -res;
return NULL; return NULL;
} }

View file

@ -87,7 +87,7 @@ static char *find_module(const char *path, const char *name)
newpath = spa_aprintf("%s/%s", path, entry->d_name); newpath = spa_aprintf("%s/%s", path, entry->d_name);
if (newpath == NULL) if (newpath == NULL)
return NULL; break;
if (stat(newpath, &s) == 0 && S_ISDIR(s.st_mode)) { if (stat(newpath, &s) == 0 && S_ISDIR(s.st_mode)) {
filename = find_module(newpath, name); filename = find_module(newpath, name);

View file

@ -43,8 +43,11 @@ static int add_func(struct pw_properties *this, char *key, char *value)
struct properties *impl = SPA_CONTAINER_OF(this, struct properties, this); struct properties *impl = SPA_CONTAINER_OF(this, struct properties, this);
item = pw_array_add(&impl->items, sizeof(struct spa_dict_item)); item = pw_array_add(&impl->items, sizeof(struct spa_dict_item));
if (item == NULL) if (item == NULL) {
free(key);
free(value);
return -errno; return -errno;
}
item->key = key; item->key = key;
item->value = value; item->value = value;

View file

@ -1182,12 +1182,15 @@ pw_stream_new_simple(struct pw_loop *loop,
return NULL; return NULL;
context = pw_context_new(loop, NULL, 0); context = pw_context_new(loop, NULL, 0);
if (context == NULL) if (context == NULL) {
return NULL; res = -errno;
goto error_cleanup;
}
impl = stream_new(context, name, props, NULL); impl = stream_new(context, name, props, NULL);
if (impl == NULL) { if (impl == NULL) {
res = -errno; res = -errno;
props = NULL;
goto error_cleanup; goto error_cleanup;
} }
@ -1198,7 +1201,10 @@ pw_stream_new_simple(struct pw_loop *loop,
return this; return this;
error_cleanup: error_cleanup:
pw_context_destroy(context); if (context)
pw_context_destroy(context);
if (props)
pw_properties_free(props);
errno = -res; errno = -res;
return NULL; return NULL;
} }
@ -1390,7 +1396,7 @@ pw_stream_connect(struct pw_stream *stream,
{ {
struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this); struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this);
struct pw_impl_factory *factory; struct pw_impl_factory *factory;
struct pw_properties *props; struct pw_properties *props = NULL;
struct pw_impl_node *follower; struct pw_impl_node *follower;
const char *str; const char *str;
uint32_t i; uint32_t i;
@ -1520,6 +1526,7 @@ pw_stream_connect(struct pw_stream *stream,
} }
} else { } else {
impl->node = follower; impl->node = follower;
pw_properties_free(props);
} }
if (!SPA_FLAG_IS_SET(impl->flags, PW_STREAM_FLAG_INACTIVE)) if (!SPA_FLAG_IS_SET(impl->flags, PW_STREAM_FLAG_INACTIVE))
pw_impl_node_set_active(impl->node, true); pw_impl_node_set_active(impl->node, true);