]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
don't leak memory in test examples
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 19 Mar 2008 14:53:13 +0000 (15:53 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 21 Mar 2008 11:58:40 +0000 (12:58 +0100)
test.c
testgrid.c

diff --git a/test.c b/test.c
index 50483ac8802bc255475b65d94598a18729ee0191..03ea040e394ed93dad6afffde551f1c3b23b3797 100644 (file)
--- a/test.c
+++ b/test.c
@@ -138,14 +138,9 @@ int main(void) {
        }
     } while (es.reason != NEWT_EXIT_COMPONENT || es.u.co == b2);
 
-    scaleVal = strdup(scaleVal);
-    enr2 = strdup(enr2);
-    enr3 = strdup(enr3);
-
+    numsel = 0;
     selectedList = newtListboxGetSelection(lb, &numsel);
 
-    newtFormDestroy(f);
-
     newtPopWindow();
     newtPopWindow();
     newtFinished();
@@ -154,11 +149,14 @@ int main(void) {
     printf("got string 2: %s\n", enr2);
     printf("got string 3: %s\n", enr3);
 
+    newtFormDestroy(f);
+
     printf("\nSelected listbox items (%d):\n", numsel);
     if(selectedList) {
        for(i = 0; i < numsel; i++)
            printf("#%d\n", (int)(long) selectedList[i]);
     }
+    free(selectedList);
 
     return 0;
 }
index 0d3aa85f9278219d4f9fc7c6b0f918d8b49238f6..a2aa3d27570c15806bcc4852bd9a84f9e09062af 100644 (file)
@@ -10,9 +10,9 @@ int main(void) {
     newtComponent answer, f, t;
     newtGrid grid, subgrid;
     char * flowedText;
-    int textWidth, textHeight, rc;
+    int textWidth, textHeight, rc, i;
     char * menuContents[] = { "One", "Two", "Three", "Four", "Five", NULL };
-    const char * entries[10];
+    char * entries[10];
     struct newtWinEntry autoEntries[] = {
        { "An entry", entries + 0, 0 },
        { "Another entry", entries + 1, 0 },
@@ -97,6 +97,8 @@ int main(void) {
                     "newtWinEntries() call. It lets you get a lot of input "
                     "quite easily.", 50, 5, 5, 20, autoEntries, "Ok", 
                     "Cancel", NULL);
+    for (i = 0; i < sizeof (autoEntries) / sizeof (struct newtWinEntry) && autoEntries[i].value; i++)
+           free(*(autoEntries[i].value));
 
     newtFinished();