From f7a354ed7056517d62b7661e38dd1bd30c47d4f3 Mon Sep 17 00:00:00 2001 From: mlichvar Date: Thu, 12 Apr 2007 17:03:57 +0000 Subject: [PATCH] - fix some memory leaks --- checkboxtree.c | 18 +++++++++++++----- newt.spec | 1 + testtree.c | 3 +++ textbox.c | 4 ++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/checkboxtree.c b/checkboxtree.c index 290a2e5..e574d55 100644 --- a/checkboxtree.c +++ b/checkboxtree.c @@ -531,19 +531,26 @@ static void ctDraw(newtComponent co) { (*ct->currItem ? (*ct->currItem)->depth : 0) * 3 + 4); } -static void ctDestroy(newtComponent co) { - struct CheckboxTree * ct = co->data; - struct items * item, * nextitem; - - nextitem = item = ct->itemlist; +static void destroyItems(struct items * item) { + struct items * nextitem; while (item != NULL) { nextitem = item->next; free(item->text); + if (item->branch) + destroyItems(item->branch); free(item); item = nextitem; } +} +static void ctDestroy(newtComponent co) { + struct CheckboxTree * ct = co->data; + + destroyItems(ct->itemlist); + free(ct->flatList); + if (ct->sb) + ct->sb->ops->destroy(ct->sb); free(ct->seq); free(ct); free(co); @@ -802,6 +809,7 @@ void newtCheckboxTreeSetCurrent(newtComponent co, void * data) { treeTop = item->branch; } + free(path); buildFlatList(co); item = findItem(ct->itemlist, data); diff --git a/newt.spec b/newt.spec index c05ac6b..cf7d76a 100644 --- a/newt.spec +++ b/newt.spec @@ -90,6 +90,7 @@ rm -rf $RPM_BUILD_ROOT %changelog - fix cursor positioning when setting entry or checkbox flags - fix counting of items in checkboxtree +- fix some memory leaks - fix entry scrolling (#234829) - fix multibyte character handling in entry diff --git a/testtree.c b/testtree.c index 62494b8..8dfcca3 100644 --- a/testtree.c +++ b/testtree.c @@ -118,6 +118,8 @@ int main(void) { j = (int) *ptr++; printf("%d\n", j); } + free(result); + result = newtCheckboxTreeGetMultiSelection(checktree, &numselected, 'b'); ptr = result; if (!result || !numselected) @@ -137,6 +139,7 @@ int main(void) { for (i = 0; list && list[i] != NEWT_ARG_LAST; i++) printf(" %d", list[i]); printf("\n"); + free(list); newtFormDestroy(form); diff --git a/textbox.c b/textbox.c index b2593c1..fcfb41f 100644 --- a/textbox.c +++ b/textbox.c @@ -451,6 +451,10 @@ static void textboxDestroy(newtComponent co) { int i; struct textbox * tb = co->data; + if (tb->sb) + tb->sb->ops->destroy(tb->sb); + if (tb->sb_act) + tb->sb_act->ops->destroy(tb->sb_act); for (i = 0; i < tb->numLines; i++) free(tb->lines[i]); free(tb->lines); -- 2.47.2