From 315aaabbce6b2db52ff5796708b777b488fd848e Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 20 May 2014 18:25:58 +1000 Subject: The results of a session with valgrind. I'm surprised that this highly experimental code, built with chewing gum and chicken wire, had so little problems, and most of those where leaks. The majority of problems reported are from external libraries. --- src/GuiLua/GuiLua.c | 5 +++-- src/LuaSL/LuaSL_compile.c | 3 ++- src/extantz/Evas_3D_demo.c | 1 - src/extantz/camera.c | 1 + src/extantz/ephysics_demo.c | 5 ++--- src/extantz/extantz.c | 6 ++++-- src/extantz/extantz.h | 1 + src/extantz/scenri.c | 17 +++++++++++++++-- src/extantz/woMan.c | 2 ++ src/libraries/Runnr.c | 22 ++++++++++++---------- src/libraries/SledjHamr.c | 3 +++ src/libraries/winFang.c | 15 ++++++++++----- src/love/love.c | 11 +++++++++++ 13 files changed, 66 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index 2fa9bcb..5815b45 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c @@ -204,6 +204,7 @@ static int action(lua_State *L) if (wid && strcmp(wid->magic, "Widget") == 0) { //PD("Setting action : %s\n", action); + free(wid->action); wid->action = strdup(action); } return 0; @@ -302,7 +303,7 @@ static int window(lua_State *L) } win = winFangAdd(parent, 5, 26, w, h, title, name, world); - win->module = module; + win->module = strdup(module); if (gl) { // If there's no parent, we become the parent. @@ -418,7 +419,7 @@ PD("GuiLua 3"); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "loopWindow", "Run our windows main loop.", loopWindow, 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "quit", "Quit, exit, remove thyself.", quit, 0); - push_lua(L, "@ ( = $ $ & $ )", skang, THINGASM, skang, "closeWindow", "Closes a window.", closeWindow, "userdata", 0); // TODO - closeWindow, "userdata"); + push_lua(L, "@ ( = $ $ & $ )", skang, THINGASM, skang, "closeWindow", "Closes a window.", closeWindow, "userdata", 0); // A test of the array building stuff. push_lua(L, "@ ( { = $ $ % $widget !required } )", skang, THINGASM, skang, "wibble", "It's wibbly!", 1, "'edit', 'The wibblinator:', 1, 1, 10, 50", 1, 0); diff --git a/src/LuaSL/LuaSL_compile.c b/src/LuaSL/LuaSL_compile.c index c6ac70a..4fe5671 100644 --- a/src/LuaSL/LuaSL_compile.c +++ b/src/LuaSL/LuaSL_compile.c @@ -985,6 +985,7 @@ LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifi { func->state = result->name.text; } + eina_iterator_free(handlers); result->block = block->value.blockValue; if (state) { @@ -1541,7 +1542,7 @@ static void outputRawParenthesisToken(FILE *file, outputMode mode, LSL_Parenthes else outputLeaf(file, mode, parenthesis->contents); if ((OM_LUA == mode) && (MF_WRAPFUNC & parenthesis->flags)) - // TODO - Need to fetc the identifier before, but we only have one in my test code, so fake it. + // TODO - Need to fetch the identifier before, but we only have one in my test code, so fake it. fprintf(file, "; return ix; end)() "); else { diff --git a/src/extantz/Evas_3D_demo.c b/src/extantz/Evas_3D_demo.c index fb6f03f..3dda9ef 100644 --- a/src/extantz/Evas_3D_demo.c +++ b/src/extantz/Evas_3D_demo.c @@ -456,7 +456,6 @@ void Evas_3D_Demo_add(globals *ourGlobals) void Evas_3D_Demo_fini(globals *ourGlobals) { - eo_unref(ourGlobals->scene->image); free(sphere_vertices); free(sphere_indices); } diff --git a/src/extantz/camera.c b/src/extantz/camera.c index 83bf98a..b7a79d1 100644 --- a/src/extantz/camera.c +++ b/src/extantz/camera.c @@ -235,6 +235,7 @@ Evas_3D_Node *cameraAdd(Evas *evas, Scene_Data *scene, Evas_Object *image) // evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 20.0, EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0) evas_3d_node_orientation_set(0.0, 0.0, 0.0, 1.0) ); +// eo_unref(camera); eo_do(scene->root_node, evas_3d_node_member_add(result)); eo_do(scene->scene, evas_3d_scene_camera_node_set(result)); diff --git a/src/extantz/ephysics_demo.c b/src/extantz/ephysics_demo.c index 6ace8a0..a0bf4d0 100644 --- a/src/extantz/ephysics_demo.c +++ b/src/extantz/ephysics_demo.c @@ -34,7 +34,7 @@ EPhysics_World *ephysicsAdd(globals *ourGlobals) sprintf(buf, "%s/%s.edj", elm_app_data_dir_get(), EPHYSICS_TEST_THEME); box1 = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win, - elm_obj_image_file_set(strdup(buf), "blue-cube"), + elm_obj_image_file_set(buf, "blue-cube"), evas_obj_size_set(70, 70), evas_obj_position_set(ourGlobals->win_w / 2 - 80, ourGlobals->win_h - 200), evas_obj_visibility_set(EINA_TRUE) @@ -49,10 +49,9 @@ EPhysics_World *ephysicsAdd(globals *ourGlobals) ephysics_body_sleeping_threshold_set(box_body1, 0.1, 0.1); eo_unref(box1); - sprintf(buf, "%s/%s.edj", elm_app_data_dir_get(), EPHYSICS_TEST_THEME); box2 = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win, - elm_obj_image_file_set(strdup(buf), "purple-cube"), + elm_obj_image_file_set(buf, "purple-cube"), evas_obj_size_set(70, 70), evas_obj_position_set(ourGlobals->win_w / 2 + 10, ourGlobals->win_h - 200), evas_obj_visibility_set(EINA_TRUE) diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index ff418c0..fa38251 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -606,8 +606,6 @@ EAPI_MAIN int elm_main(int argc, char **argv) ourGlobals.ee = ecore_evas_ecore_evas_get(ourGlobals.evas); // Only use this on Evas that was created with Ecore_Evas. #endif - evas_object_event_callback_add(ourGlobals.win, EVAS_CALLBACK_RESIZE, _on_resize, &ourGlobals); - // Get the screen size. elm_win_screen_size_get(ourGlobals.win, &ourGlobals.win_x, &ourGlobals.win_y, &ourGlobals.scr_w, &ourGlobals.scr_h); ourGlobals.win_x = ourGlobals.win_x + (ourGlobals.scr_w / 3); @@ -616,6 +614,8 @@ EAPI_MAIN int elm_main(int argc, char **argv) evas_object_move(ourGlobals.win, ourGlobals.win_x, ourGlobals.win_y); evas_object_resize(ourGlobals.win, ourGlobals.win_w, ourGlobals.win_h); + evas_object_event_callback_add(ourGlobals.win, EVAS_CALLBACK_RESIZE, _on_resize, &ourGlobals); + /* Our "layers". TODO - This is out of date, I should update it. Elm win - our real main window @@ -694,7 +694,9 @@ EAPI_MAIN int elm_main(int argc, char **argv) if (ourGlobals.win) { + ecore_animator_del(ourGlobals.animator); Evas_3D_Demo_fini(&ourGlobals); + scenriDel(ourGlobals.scene); eo_unref(ourGlobals.tb); winFangDel(ourGlobals.mainWindow); } diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h index d77c764..a41f4e0 100644 --- a/src/extantz/extantz.h +++ b/src/extantz/extantz.h @@ -264,6 +264,7 @@ void Evas_3D_Demo_fini(globals *ourGlobals); Scene_Data *scenriAdd(Evas_Object *win); Evas_3D_Node *cameraAdd(Evas *evas, Scene_Data *scene, Evas_Object *win); Eina_Bool animateCamera(Scene_Data *scene); +void scenriDel(Scene_Data *scene); winFang *filesAdd(globals *ourGlobals, char *path, Eina_Bool multi, Eina_Bool save); void filesShow(winFang *me, Evas_Smart_Cb func, void *data); diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c index eaec88e..0210a48 100644 --- a/src/extantz/scenri.c +++ b/src/extantz/scenri.c @@ -143,7 +143,20 @@ Scene_Data *scenriAdd(Evas_Object *win) return scene; } -void scenriDel(globals *ourGlobals) +void scenriDel(Scene_Data *scene) { - eo_unref(ourGlobals->scene->image); + // TODO - I should probably free up all this Evas_3D stuff. Oddly Eo doesn't bitch about it, only valgrind. + // Eo bitches if they are unref'd here. + // So either Eo or valgrind bitches, depending on what I do. I'll leave them commented out, let valgrind bitch, and blame Evas_3D. +// eo_unref(scene->light_node); +// eo_unref(scene->light); + + // TODO - Should have a separate cameraDel() for these. + free(scene->move); +// eo_unref(scene->camera_node); + + eo_unref(scene->image); + eo_unref(scene->scene); +// eo_unref(scene->root_node); + free(scene); } diff --git a/src/extantz/woMan.c b/src/extantz/woMan.c index 64df84c..ef10631 100644 --- a/src/extantz/woMan.c +++ b/src/extantz/woMan.c @@ -245,6 +245,7 @@ winFang *woMan_add(globals *ourGlobals) viewer_gic->func.del = NULL; for (i = 0; NULL != viewerTest[i][0]; i++) { + // TODO - Should free this later, but this entire thing needs a rewrite anyway. ezViewer *thisViewer = calloc(1, sizeof(ezViewer)); if (thisViewer) @@ -265,6 +266,7 @@ winFang *woMan_add(globals *ourGlobals) sprintf(buf, "%s/%s", elm_app_data_dir_get(), img3); tab = viewerList; tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Viewers", _promote, tab_it); + // TODO - This strdup leaks, but this is just temporary test code anyway, it will go away. tab = _content_image_new(me->win, strdup(buf)); tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Landmarks", _promote, tab_it); tab = gridList; tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Grids", _promote, tab_it); elm_layout_box_append(me->win, WF_BOX, nf); diff --git a/src/libraries/Runnr.c b/src/libraries/Runnr.c index b775e19..72bc523 100644 --- a/src/libraries/Runnr.c +++ b/src/libraries/Runnr.c @@ -151,6 +151,9 @@ static char *_push_name(lua_State *L, char *q, int *idx) // Stack usage [-0, +1 return q; } +/* It's the callers job to stash things safely before returning from the Lua to C function call. + * Coz things like strings might go away after the stack is freed. + */ int pull_lua(lua_State *L, int i, char *params, ...) // Stack usage - // if i is a table // [-n, +n, e] @@ -210,16 +213,15 @@ int pull_lua(lua_State *L, int i, char *params, ...) // Stack usage - if (lua_isstring(L, j)) // Stack usage [-0, +0, -] { char **v = va_arg(vl, char **); - size_t len; - char *temp = (char *) lua_tolstring(L, j, &len); // Stack usage [-0, +0, m] - - len++; // Cater for the null at the end. - *v = malloc(len); - if (*v) - { - memcpy(*v, temp, len); - n++; - } + + // We could strdup the string, but that causes leaks. + // The problem is that the caller doesn't know if we allocated or not, + // since the incoming pointer could already be pointing to a default value. + // Lua says the string is valid until it's popped off the stack, + // and this is used only in calls to C functions from Lua. + // So just document that it's the callers job to stash it safely if needed after returning. + *v = (char *) lua_tostring(L, j); + n++; } break; } diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c index 7fcede7..5f26fde 100644 --- a/src/libraries/SledjHamr.c +++ b/src/libraries/SledjHamr.c @@ -47,6 +47,9 @@ static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev) } if (ev->server) ecore_con_server_del(ev->server); + // TODO - Hmm, I think this is where this should be freed, but it causes a seggie in reachOut's while loop. + // Which is odd, so leave it commented for now and investigate later. +// free(this); return ECORE_CALLBACK_CANCEL; } diff --git a/src/libraries/winFang.c b/src/libraries/winFang.c index b6ceee9..bfd9327 100644 --- a/src/libraries/winFang.c +++ b/src/libraries/winFang.c @@ -369,28 +369,29 @@ void winFangCalcMinSize(winFang *win) void winFangDel(winFang *win) { - winFang *wf; - Widget *wid; + winFang *wf, *wf2; + Widget *wid, *wid2; if (!win) return; if (win->bg) eo_unref(win->bg); if (win->grid) eo_unref(win->grid); if (win->layout) eo_unref(win->layout); - EINA_CLIST_FOR_EACH_ENTRY(wf, &win->winFangs, winFang, node) + EINA_CLIST_FOR_EACH_ENTRY_SAFE(wf, wf2, &win->winFangs, winFang, node) { winFangDel(wf); } // Elm will delete our widgets, but if we are using eo, we need to unref them. - EINA_CLIST_FOR_EACH_ENTRY(wid, &win->widgets, Widget, node) + EINA_CLIST_FOR_EACH_ENTRY_SAFE(wid, wid2, &win->widgets, Widget, node) { if (wid->on_del) wid->on_del(wid, wid->obj, NULL); widgetDel(wid); - eo_unref(wid->obj); } if (win->on_del) win->on_del(win, win->win, NULL); evas_object_del(win->win); + free(win->module); + free(win); } @@ -483,10 +484,14 @@ void widgetDel(Widget *wid) { if (wid) { + free(wid->action); + free(wid->label); // TODO - This is to work around a bug in Elm entry, remove it when the bug is fixed. // The bug is that editable entry widgets cause the app to hang on exit. if (strcmp(WT_ENTRY, wid->type) == 0) elm_entry_editable_set(wid->obj, EINA_FALSE); + eo_unref(wid->obj); + free(wid); } } diff --git a/src/love/love.c b/src/love/love.c index 91c9d95..0e4ac40 100644 --- a/src/love/love.c +++ b/src/love/love.c @@ -142,6 +142,9 @@ static void dirList_compile(const char *name, const char *path, void *data) { if (0 == strcmp(ext, ".lsl")) { + // TODO - We are leaking these, coz we don't know when scripts get deleted in the script server. + // On the other hand, the main use for this is a temporary hack that sends events to all scripts. + // So that part will get a rewrite when we make it real later anyway. script *me = calloc(1, sizeof(script)); scriptCount++; @@ -388,6 +391,7 @@ static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *e { sendForth(ourGlobals->serverLuaSL, me->SID, "events.link_message%s", &command[15]); } + eina_iterator_free(scripts); } else if (0 == strncmp(command, "llGetNotecardLine(", 18)) { @@ -421,6 +425,7 @@ static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *e temp = NULL; do { + free(temp); temp = get_rawline(fd, &len, '\n'); if (temp) { @@ -455,6 +460,8 @@ static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *e else sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", \"EndOfFuckingAround\")", key); } + eina_iterator_free(scripts); + free(temp); close(fd); } @@ -545,6 +552,7 @@ static Eina_Bool _dataClient(void *data, int type, Ecore_Con_Event_Client_Data * sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedNames({\"%s\"})", ownerName); sendForth(ourGlobals->serverLuaSL, me->SID, "events.touch_start(1)"); } + eina_iterator_free(scripts); } else if (0 == strncmp(command, "events.listen(", 14)) { @@ -557,6 +565,7 @@ static Eina_Bool _dataClient(void *data, int type, Ecore_Con_Event_Client_Data * { sendForth(ourGlobals->serverLuaSL, me->SID, command); } + eina_iterator_free(scripts); } else PW("Unknown command from client - %s", command); @@ -768,6 +777,8 @@ int main(int argc, char **argv) } else PC("Failed to init ecore_con!"); + + eina_hash_free(ourGlobals.scripts); } else fprintf(stderr, "Failed to init eina!"); -- cgit v1.1