menuconfig: Fix memory leak introduced by jump keys feature
authorBenjamin Poirier <bpoirier@suse.de>
Mon, 15 Apr 2013 14:13:50 +0000 (10:13 -0400)
committerYann E. MORIN <yann.morin.1998@free.fr>
Tue, 16 Apr 2013 19:59:28 +0000 (21:59 +0200)
Fixes the memory leak of struct jump_key allocated in get_prompt_str()

Signed-off-by: Benjamin Poirier <bpoirier@suse.de>
Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: stable@vger.kernel.org
scripts/kconfig/list.h
scripts/kconfig/mconf.c

index 0ae730be5f49d87025601300ba3a7bb86110f3eb..b87206cc92f464650fad3a8ee4178ecfee6cf973 100644 (file)
@@ -50,6 +50,19 @@ struct list_head {
             &pos->member != (head);    \
             pos = list_entry(pos->member.next, typeof(*pos), member))
 
+/**
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @pos:       the type * to use as a loop cursor.
+ * @n:         another type * to use as temporary storage
+ * @head:      the head for your list.
+ * @member:    the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe(pos, n, head, member)                 \
+       for (pos = list_entry((head)->next, typeof(*pos), member),      \
+               n = list_entry(pos->member.next, typeof(*pos), member); \
+            &pos->member != (head);                                    \
+            pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
 /**
  * list_empty - tests whether a list is empty
  * @head: the list to test.
index 566288a763709e1c6c6fb138ad2162a54a4b12c6..c5418d622a05a8a13fb165b9fc4b596fc447216e 100644 (file)
@@ -389,6 +389,7 @@ again:
                        .targets = targets,
                        .keys = keys,
                };
+               struct jump_key *pos, *tmp;
 
                res = get_relations_str(sym_arr, &head);
                dres = show_textbox_ext(_("Search Results"), (char *)
@@ -402,6 +403,8 @@ again:
                                again = true;
                        }
                str_free(&res);
+               list_for_each_entry_safe(pos, tmp, &head, entries)
+                       free(pos);
        } while (again);
        free(sym_arr);
        str_free(&title);