Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: John Lindgren <john.lindgren@tds.net>
To: alsa-devel@alsa-project.org
Subject: Re: [PATCH] Memory leak in namehint.c
Date: Tue, 20 Jul 2010 18:38:37 -0400	[thread overview]
Message-ID: <4C46256D.7070201@tds.net> (raw)
In-Reply-To: <4C45F868.7060807@tds.net>

Please disregard the previous patch as it has the potential for a double
free() if snd_card_get_name() fails.  Here is a corrected patch.

Signed-off-by: John Lindgren <john.lindgren@tds.net>
---

 src/control/namehint.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/control/namehint.c b/src/control/namehint.c
index 78572d8..1819292 100644
--- a/src/control/namehint.c
+++ b/src/control/namehint.c
@@ -471,6 +471,8 @@ static int get_card_name(struct hint_list *list, int card)
        char scard[16], *s;
        int err;
 
+       free(list->cardname);
+       list->cardname = NULL;
        err = snd_card_get_name(card, &list->cardname);
        if (err <= 0)
                return 0;


On 07/20/2010 03:26 PM, John Lindgren wrote:
> get_card_name() can be called more than once on the same list, so it
> must free the previous list->cardname before replacing it.
>
> Signed-off-by: John Lindgren <john.lindgren@tds.net>
> ---
>
>  src/control/namehint.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/src/control/namehint.c b/src/control/namehint.c
> index 78572d8..fc1cb27 100644
> --- a/src/control/namehint.c
> +++ b/src/control/namehint.c
> @@ -471,6 +471,8 @@ static int get_card_name(struct hint_list *list, int card)
>         char scard[16], *s;
>         int err;
>  
> +       if (list->cardname)
> +               free(list->cardname);
>         err = snd_card_get_name(card, &list->cardname);
>         if (err <= 0)
>                 return 0;
>   

  reply	other threads:[~2010-07-20 22:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-20 19:26 [PATCH] Memory leak in namehint.c John Lindgren
2010-07-20 22:38 ` John Lindgren [this message]
2010-07-21  7:28   ` Jaroslav Kysela

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=4C46256D.7070201@tds.net \
    --to=john.lindgren@tds.net \
    --cc=alsa-devel@alsa-project.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox