All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: John Lindgren <john.lindgren@tds.net>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH] alsa-lib: snd_device_name_hint misbehaving
Date: Tue, 03 Nov 2009 08:09:34 +0100	[thread overview]
Message-ID: <s5hocnk9j9t.wl%tiwai@suse.de> (raw)
In-Reply-To: <1257184700.1937.8.camel@dark-knight>

At Mon, 02 Nov 2009 12:58:20 -0500,
John Lindgren wrote:
> 
> On Mon, 2009-11-02 at 15:55 +0100, Takashi Iwai wrote:
> > Thanks.  I guess this depends on the config files.
> > Could you attach your ones?
> 
> I can reproduce with only the stock /usr/share/alsa/alsa.conf from
> Debian installed if I try to use the "null" device after
> snd_device_name_hint.  /usr/share/alsa/alsa.conf is attached.

Thanks!  I could reproduce the problem on my machine, too.

Now I think I found the culprit.  This is not in the core conf.c code,
but it's in namehint.c.  Try the patch below.

The point is that the variable "res" can be two different instances
in try_config().  One is the result of snd_config_search_definition().
In this case, res is the copied (expanded) objects.

This one is freed in the middle of try_config(), and then res is
assigned again to another one by snd_config_search_alias_hooks().
This guy is no expanded object but a reference.

However, the original code calls snd_config_free(res) no matter which
object is.  So, freeing the latter one results in the breakage of the
config tree.

The patch adds the check of the object type to be freed or not.


Takashi

---
diff --git a/src/control/namehint.c b/src/control/namehint.c
index e878f83..a134ed7 100644
--- a/src/control/namehint.c
+++ b/src/control/namehint.c
@@ -219,6 +219,7 @@ static int try_config(struct hint_list *list,
 	const char *str;
 	int err = 0, level;
 	long dev = list->device;
+	int cleanup_res = 0;
 
 	list->device_input = -1;
 	list->device_output = -1;
@@ -244,6 +245,7 @@ static int try_config(struct hint_list *list,
 	snd_lib_error_set_handler(eh);
 	if (err < 0)
 		goto __skip_add;
+	cleanup_res = 1;
 	err = -EINVAL;
 	if (snd_config_get_type(res) != SND_CONFIG_TYPE_COMPOUND)
 		goto __cleanup;
@@ -330,6 +332,7 @@ static int try_config(struct hint_list *list,
 	    	goto __hint;
 	snd_config_delete(res);
 	res = NULL;
+	cleanup_res = 0;
 	if (strchr(buf, ':') != NULL)
 		goto __ok;
 	/* find, if all parameters have a default, */
@@ -379,7 +382,7 @@ static int try_config(struct hint_list *list,
 	      	err = hint_list_add(list, buf, buf1);
 	}
       __skip_add:
-      	if (res)
+	if (res && cleanup_res)
 	      	snd_config_delete(res);
 	if (buf1)
 		free(buf1);

  reply	other threads:[~2009-11-03  7:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-02  2:23 [PATCH] alsa-lib: snd_device_name_hint misbehaving John Lindgren
2009-11-02  6:21 ` Jaroslav Kysela
2009-11-02 18:12   ` John Lindgren
2009-11-03  7:13     ` Takashi Iwai
2009-11-02  6:49 ` Raymond Yau
2009-11-02 13:08 ` Takashi Iwai
2009-11-02 14:43   ` John Lindgren
2009-11-02 14:55     ` Takashi Iwai
2009-11-02 17:58       ` John Lindgren
2009-11-03  7:09         ` Takashi Iwai [this message]
2009-11-03  8:03           ` Takashi Iwai
2009-11-03 15:28             ` John Lindgren
2009-11-03 15:48               ` Jaroslav Kysela
2009-11-02 18:23 John Lindgren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hocnk9j9t.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=john.lindgren@tds.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.