From 579c4dac34546357a5fd1dfd67712df6a5930bf6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 7 Apr 2015 21:23:23 +0200 Subject: audio: change a detail about filter insertion The af_add() function has a problem: if the inserted filter returns AF_DETACH during init, the function will have a dangling pointer. Until now this was avoided by making sure none of the used filters actually return AF_DETACH, but it's getting infeasible. Solve this by requiring passing an unique label to af_add(), which is then used instead of the pointer. --- audio/filter/af.c | 17 ++++++++++------- audio/filter/af.h | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'audio/filter') diff --git a/audio/filter/af.c b/audio/filter/af.c index 2889e87bb7..48f6d58868 100644 --- a/audio/filter/af.c +++ b/audio/filter/af.c @@ -689,8 +689,14 @@ int af_init(struct af_stream *s) to the stream s. The filter will be inserted somewhere nice in the list of filters. The return value is a pointer to the new filter, If the filter couldn't be added the return value is NULL. */ -struct af_instance *af_add(struct af_stream *s, char *name, char **args) +struct af_instance *af_add(struct af_stream *s, char *name, char *label, + char **args) { + assert(label); + + if (af_find_by_label(s, label)) + return NULL; + struct af_instance *new; // Insert the filter somewhere nice if (af_is_conversion_filter(s->first->next)) @@ -699,17 +705,14 @@ struct af_instance *af_add(struct af_stream *s, char *name, char **args) new = af_prepend(s, s->first->next, name, args); if (!new) return NULL; + new->label = talloc_strdup(new, label); // Reinitalize the filter list if (af_reinit(s) != AF_OK) { - af_remove(s, new); - if (af_reinit(s) != AF_OK) { - af_uninit(s); - af_init(s); - } + af_remove_by_label(s, label); return NULL; } - return new; + return af_find_by_label(s, label); } struct af_instance *af_find_by_label(struct af_stream *s, char *label) diff --git a/audio/filter/af.h b/audio/filter/af.h index 4c67208123..65a30f7dd1 100644 --- a/audio/filter/af.h +++ b/audio/filter/af.h @@ -141,7 +141,8 @@ struct af_stream *af_new(struct mpv_global *global); void af_destroy(struct af_stream *s); int af_init(struct af_stream *s); void af_uninit(struct af_stream *s); -struct af_instance *af_add(struct af_stream *s, char *name, char **args); +struct af_instance *af_add(struct af_stream *s, char *name, char *label, + char **args); int af_remove_by_label(struct af_stream *s, char *label); struct af_instance *af_find_by_label(struct af_stream *s, char *label); struct af_instance *af_control_any_rev(struct af_stream *s, int cmd, void *arg); -- cgit v1.2.3