Skip to contentSkip to conversation

Memory leak in namehint.c

PATCH Applied John Lindgren 2 participants 3 messages Jul 20, 2010 – Jul 21, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Memory leak in namehint.c

get_card_name() can be called more than once on the same list, so it must free the previous list->cardname before replacing it.

---

 src/control/namehint.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
src/control/namehint.c +2 -0
index 78572d8..fc1cb27 100644
@@ -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;
#1 lore raw

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.

---

 src/control/namehint.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
src/control/namehint.c +2 -0
index 78572d8..1819292 100644
@@ -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;
Quoted 23 lines · John Lindgren

get_card_name() can be called more than once on the same list, so it must free the previous list->cardname before replacing it.

---

 src/control/namehint.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
src/control/namehint.c +2 -0
index 78572d8..fc1cb27 100644
@@ -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;
#2 lore raw
Quoted 2 lines · John Lindgren

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.

Applied. Thanks.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.