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/libraries/Runnr.c | 22 ++++++++++++---------- src/libraries/SledjHamr.c | 3 +++ src/libraries/winFang.c | 15 ++++++++++----- 3 files changed, 25 insertions(+), 15 deletions(-) (limited to 'src/libraries') 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); } } -- cgit v1.1