diff --git a/asterisk.c b/asterisk.c
index d20f0aaaac8b403ef69b8c38283a4c8ac13ee90a..d3fbe528bbc44a056a7d4cf792aef1e76218e6d5 100755
--- a/asterisk.c
+++ b/asterisk.c
@@ -585,6 +585,10 @@ static void quit_handler(int num, int nice, int safeshutdown, int restart)
 		if (option_verbose || option_console)
 			ast_verbose("Restarting Asterisk NOW...\n");
 		restartnow = 1;
+
+		/* close logger */
+		close_logger();
+
 		/* If there is a consolethread running send it a SIGHUP 
 		   so it can execvp, otherwise we can do it ourselves */
 		if (consolethread != AST_PTHREADT_NULL) {
@@ -594,6 +598,9 @@ static void quit_handler(int num, int nice, int safeshutdown, int restart)
 		} else
 			execvp(_argv[0], _argv);
 	
+	} else {
+		/* close logger */
+		close_logger();
 	}
 	exit(0);
 }
diff --git a/asterisk.h b/asterisk.h
index d221f2f9050cc046548f2b31e03fe8d4bb604602..1ceb13c77f11b2c464ae8a4725665d29058a02bf 100755
--- a/asterisk.h
+++ b/asterisk.h
@@ -40,6 +40,7 @@ extern int load_modules(void);
 extern int load_pbx(void);
 /* Provided by logger.c */
 extern int init_logger(void);
+extern void close_logger(void);
 /* Provided by frame.c */
 extern int init_framer(void);
 /* Provided by logger.c */
diff --git a/logger.c b/logger.c
index 840bbf2a34368fdb2a5473f4f3f16b294c3946e9..9ba890bd8b55bc24846bee5b42614f944cf2c141 100755
--- a/logger.c
+++ b/logger.c
@@ -428,6 +428,25 @@ int init_logger(void)
 	return -1;
 }
 
+void close_logger(void)
+{
+	struct msglist *m, *tmp;
+
+	m = list;
+	ast_mutex_lock(&msglist_lock);
+	while(m) {
+		if (m->msg) {
+			free(m->msg);
+		}
+		tmp = m->next;
+		free(m);
+		m = tmp;
+	}
+	list = last = NULL;
+	ast_mutex_unlock(&msglist_lock);
+	return;
+}
+
 static void ast_log_vsyslog(int level, const char *file, int line, const char *function, const char *fmt, va_list args) {
     char buf[BUFSIZ];