try to remove the string allocation for get_query
authorJim Morris <morris@wolfman.com>
Fri, 7 Sep 2018 13:20:59 +0000 (14:20 +0100)
committerJim Morris <morris@wolfman.com>
Fri, 7 Sep 2018 13:20:59 +0000 (14:20 +0100)
src/libs/Network/uip/Network.cpp
src/libs/Network/uip/Network.h
src/libs/Network/uip/webserver/httpd.c

index 983bbaa..3b6cf94 100644 (file)
@@ -399,8 +399,13 @@ void Network::on_main_loop(void *argument)
 
 extern "C" const char *get_query_string()
 {
-    const char* dup= strdup(THEKERNEL->get_query_string().c_str());
-    return dup;
+    return theNetwork->get_query_string();
+}
+
+const char *Network::get_query_string()
+{
+    strncpy(query_str, THEKERNEL->get_query_string().c_str(), 131);
+    return query_str;
 }
 
 // select between webserver and telnetd server
index 9f1c9e7..75aaaeb 100644 (file)
@@ -29,7 +29,7 @@ public:
         bool plan9_enabled:1;
         bool use_dhcp:1;
     };
-
+    const char *get_query_string();
 
 private:
     void init();
@@ -42,6 +42,7 @@ private:
 
     struct timer periodic_timer, arp_timer;
     char *hostname;
+    char query_str[132];
     volatile uint32_t tickcnt;
     uint8_t mac_address[6];
     uint8_t ipaddr[4];
index f9b91fd..4bdaa5b 100644 (file)
@@ -315,16 +315,6 @@ static PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
 {
     return send_headers_3(s, statushdr, 1);
 }
-static PT_THREAD(send_string(struct httpd_state *s, const char *str, int duped))
-{
-    PSOCK_BEGIN(&s->sout);
-
-    PSOCK_SEND_STR(&s->sout, str);
-    if(duped) {
-        free((void *)str);
-    }
-    PSOCK_END(&s->sout);
-}
 /*---------------------------------------------------------------------------*/
 static
 PT_THREAD(handle_output(struct httpd_state *s))
@@ -369,7 +359,7 @@ PT_THREAD(handle_output(struct httpd_state *s))
 
         if (strcmp(s->filename, "/query") == 0) { // query short cut
             PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200));
-            PT_WAIT_THREAD(&s->outputpt, send_string(s, get_query_string(), 1));
+            PSOCK_SEND_STR(&s->sout, get_query_string());
 
         } else if (!fs_open(s)) { // Note this has the side effect of opening the file
             DEBUG_PRINTF("404 file not found\n");