Index: main.c
===================================================================
--- main.c	(revision 2305)
+++ main.c	(working copy)
@@ -52,6 +52,7 @@
   struct list returnpath; /* returnpath (should aways be just 1 hop */
   int users_are_usernames = 0,i;
   u64_t dummyidx=0,dummysize=0;
+  int exitcode = 0;
 
   openlog(PNAME, LOG_PID, LOG_MAIL);
 
@@ -119,14 +120,14 @@
 	  {
 	    printf ("\nError: When using the mailbox delivery option,"
 		    " you should specify a username\n\n");
-	    return 0;
+	    goto cleanup;
           }
       }
     else
       {
 	printf ("\nError: Mailbox delivery needs a -u clause to specify"
 		" a user that should be used for delivery\n\n");
-	return 0;
+	goto cleanup;
       }
 
     trace (TRACE_INFO,"main(): using SPECIAL_DELIVERY to mailbox");
@@ -134,7 +135,8 @@
     if (list_nodeadd(&users, argv[4], strlen(argv[4])+1) == 0)
       {
 	trace (TRACE_STOP, "main(): out of memory");
-	return 1;
+	exitcode = 1;
+	goto cleanup;
       }
 
     users_are_usernames = 1;
@@ -151,7 +153,8 @@
           if (list_nodeadd(&users, argv[i], strlen(argv[i]) + 1) == 0)
 	    {
               trace(TRACE_STOP, "main(): out of memory");
-              return 1;
+              exitcode = 1;
+              goto cleanup;
 	    }
 	}
 
@@ -182,9 +185,14 @@
   trace(TRACE_DEBUG,"main(): freeing memory blocks");
   
   trace (TRACE_DEBUG,"main(): they're all free. we're done.");
-  
+
+cleanup:
+  list_freelist(&sysItems.start);
+  list_freelist(&smtpItems.start);
+  list_freelist(&mimelist.start);
+  list_freelist(&users.start);
   db_disconnect();
   auth_disconnect();
 
-  return 0;
+  return exitcode;
 }
