[PATCH] editor: Malloc check, flush stuck keyboard

Martin Minarik minarik11 at student.fiit.stuba.sk
Thu Jun 21 19:59:00 PDT 2012


The on screen keyboard stays displayed when the editor is closed.

We need to flush the display once more.

This patch adds the display_flush() method to window.c, to execute
wl_display_flush() once, not in a loop like in display_run().

It also adds the NULL checks in constructor and destructor.
---
 clients/editor.c |   23 +++++++++++++++--------
 clients/window.c |    6 ++++++
 clients/window.h |    3 +++
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/clients/editor.c b/clients/editor.c
index 145ba20..d6aa62a 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -79,6 +79,8 @@ text_entry_create(struct editor *editor, const char *text)
 	struct wl_surface *surface;
 
 	entry = malloc(sizeof *entry);
+	if (entry == NULL)
+		return NULL;
 
 	surface = window_get_wl_surface(editor->window);
 
@@ -92,14 +94,6 @@ text_entry_create(struct editor *editor, const char *text)
 }
 
 static void
-text_entry_destroy(struct text_entry *entry)
-{
-	text_model_destroy(entry->model);
-	free(entry->text);
-	free(entry);
-}
-
-static void
 text_entry_draw(struct text_entry *entry, cairo_t *cr)
 {
 	cairo_save(cr);
@@ -214,6 +208,17 @@ text_entry_deactivate(struct text_entry *entry)
 }
 
 static void
+text_entry_destroy(struct text_entry *entry)
+{
+	if (entry != NULL) {
+		text_entry_deactivate(entry);
+		text_model_destroy(entry->model);
+		free(entry->text);
+	}
+	free(entry);
+}
+
+static void
 button_handler(struct widget *widget,
 	       struct input *input, uint32_t time,
 	       uint32_t button,
@@ -297,5 +302,7 @@ main(int argc, char *argv[])
 	text_entry_destroy(editor.entry);
 	text_entry_destroy(editor.editor);
 
+	display_flush(editor.display);
+
 	return 0;
 }
diff --git a/clients/window.c b/clients/window.c
index f41812a..7330a7a 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -3732,6 +3732,12 @@ display_watch_fd(struct display *display,
 }
 
 void
+display_flush(struct display *display)
+{
+	wl_display_flush(display->display);
+}
+
+void
 display_run(struct display *display)
 {
 	struct task *task;
diff --git a/clients/window.h b/clients/window.h
index 12e4352..b6ef194 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -135,6 +135,9 @@ display_watch_fd(struct display *display,
 		 int fd, uint32_t events, struct task *task);
 
 void
+display_flush(struct display *d);
+
+void
 display_run(struct display *d);
 
 void
-- 
1.7.5.4



More information about the wayland-devel mailing list