From 6e0922b77b2dbee5712bc9371c0a3f1f34ab7657 Mon Sep 17 00:00:00 2001 From: tasn Date: Tue, 18 Oct 2011 08:58:41 +0000 Subject: [PATCH] Elm glayer: Fixed leaks in glayer's test code. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@64142 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/test_gesture_layer.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/bin/test_gesture_layer.c b/src/bin/test_gesture_layer.c index 2b6cf78..ecc1324 100644 --- a/src/bin/test_gesture_layer.c +++ b/src/bin/test_gesture_layer.c @@ -233,6 +233,24 @@ zoom_end(void *_po, void *event_info) return EVAS_EVENT_FLAG_NONE; } +static void +_win_del_req(void *data, Evas_Object *obj __UNUSED__, + void *event_info __UNUSED__) +{ + Photo_Object **photo_array = (Photo_Object **) data; + + if (!photo_array) + return; + + /* The content of the photo object is automatically deleted when the win + * is deleted. */ + for ( ; *photo_array ; photo_array++) + free(*photo_array); + + free(data); +} + + Photo_Object * photo_object_add(Evas_Object *parent, Evas_Object *ic, const char *icon, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, int angle) @@ -303,6 +321,9 @@ test_gesture_layer(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Coord w, h; Evas_Object *win, *bg; char buf[PATH_MAX]; + int ind = 0; + Photo_Object **photo_array; + photo_array = calloc(sizeof(*photo_array), 4); w = 480; h = 800; @@ -319,10 +340,10 @@ test_gesture_layer(void *data __UNUSED__, Evas_Object *obj __UNUSED__, evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_show(bg); - snprintf(buf, sizeof(buf), "%s/images/pol_sky.png", elm_app_data_dir_get()); - photo_object_add(win, NULL, buf, 200, 200, 365, 400, 0); + snprintf(buf, sizeof(buf), "%s/images/pol_sky.png", elm_app_data_dir_get()); + photo_array[ind++] = photo_object_add(win, NULL, buf, 200, 200, 365, 400, 0); snprintf(buf, sizeof(buf), "%s/images/pol_twofish.png", elm_app_data_dir_get()); - photo_object_add(win, NULL, buf, 40, 300, 365, 400, 45); + photo_array[ind++] = photo_object_add(win, NULL, buf, 40, 300, 365, 400, 45); Evas_Object *en = elm_entry_add(win); elm_entry_entry_set(en, "You can use whatever object you want, " @@ -334,8 +355,11 @@ test_gesture_layer(void *data __UNUSED__, Evas_Object *obj __UNUSED__, elm_layout_file_set(postit, buf, "main"); elm_layout_content_set(postit, "ent", en); - photo_object_add(win, postit, NULL, 50, 50, 382, 400, 355); + photo_array[ind++] = photo_object_add(win, postit, NULL, 50, 50, 382, 400, 355); + photo_array[ind] = NULL; + evas_object_smart_callback_add(win, "delete,request", _win_del_req, + photo_array); evas_object_show(win); } -- 2.7.4