[PATCH 1/9] menu: initialize entries list in menu_alloc

Sascha Hauer s.hauer at pengutronix.de
Mon Aug 23 02:24:05 EDT 2010


Otherwise menu_free fails when menu_add failed.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/menu.c  |    4 ----
 include/menu.h |    9 ++++++++-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/common/menu.c b/common/menu.c
index b201644..9c40365 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -68,10 +68,6 @@ int menu_add(struct menu *m)
 
 	list_add_tail(&m->list, &menus.list);
 
-	m->nb_entries = 0;
-
-	INIT_LIST_HEAD(&m->entries.list);
-
 	return 0;
 }
 
diff --git a/include/menu.h b/include/menu.h
index 4405ced..128d671 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -55,7 +55,14 @@ struct menu {
  */
 static inline struct menu* menu_alloc(void)
 {
-	return calloc(1, sizeof(struct menu));
+	struct menu *m;
+
+	m = calloc(1, sizeof(struct menu));
+	if (m) {
+		INIT_LIST_HEAD(&m->entries.list);
+		m->nb_entries = 0;
+	}
+	return m;
 }
 void menu_free(struct menu *m);
 int menu_add(struct menu* m);
-- 
1.7.1




More information about the barebox mailing list