diff --git a/build/test/test.pl b/build/test/test.pl
index eb8b62cdd9a9b7505f90a21d56ff248a061f3cae..5166c31e7573dfa447ae6c50bfc68594ad4650b0 100644
--- a/build/test/test.pl
+++ b/build/test/test.pl
@@ -361,8 +361,7 @@ unless (scalar(@ARGV) > 0 and $ARGV[0] eq "basic_tests") {
   o("GET /dir%20with%20spaces/hello.cgi HTTP/1.0\n\r\n",
       'HTTP/1.1 200 OK.+hello', 'CGI script with spaces in path');
   o("GET /env.cgi HTTP/1.0\n\r\n", 'HTTP/1.1 200 OK', 'GET CGI file');
-  o("GET /bad2.cgi HTTP/1.0\n\n", "HTTP/1.1 302 Please pass me to the client\r",
-    'CGI Status code text');
+  o("GET /bad2.cgi HTTP/1.0\n\n", "^HTTP/1.1 302", 'CGI Status code');
   o("GET /sh.cgi HTTP/1.0\n\r\n", 'shell script CGI',
     'GET sh CGI file') unless on_windows();
   o("GET /env.cgi?var=HELLO HTTP/1.0\n\n", 'QUERY_STRING=var=HELLO',
diff --git a/mongoose.c b/mongoose.c
index e972d2941eb08e1582e70873a1ab98c248b48e87..95ecb183849f60793d99998f836166cde3745b83 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -3532,6 +3532,7 @@ unsigned int mg_poll_server(struct mg_server *server, int milliseconds) {
 }
 
 void mg_destroy_server(struct mg_server **server) {
+  int i;
   struct ll *lp, *tmp;
 
   if (server != NULL && *server != NULL) {
@@ -3542,8 +3543,12 @@ void mg_destroy_server(struct mg_server **server) {
       free(LINKED_LIST_ENTRY(lp, struct connection, link));
     }
     LINKED_LIST_FOREACH(&(*server)->uri_handlers, lp, tmp) {
+      free(LINKED_LIST_ENTRY(lp, struct uri_handler, link)->uri);
       free(LINKED_LIST_ENTRY(lp, struct uri_handler, link));
     }
+    for (i = 0; i < (int) ARRAY_SIZE((*server)->config_options); i++) {
+      free((*server)->config_options[i]);  // It is OK to free(NULL)
+    }
 #ifdef USE_SSL
     if ((*server)->ssl_ctx != NULL) SSL_CTX_free((*server)->ssl_ctx);
 #endif