Prechádzať zdrojové kódy

httpd: post example: free pbuf in httpd_post_receive_data

See bug #57742

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
Simon Goldschmidt 6 rokov pred
rodič
commit
3034e9fad0

+ 12 - 2
contrib/examples/httpd/post_example/post_example.c

@@ -91,6 +91,10 @@ httpd_post_begin(void *connection, const char *uri, const char *http_request,
 err_t
 httpd_post_receive_data(void *connection, struct pbuf *p)
 {
+  err_t ret;
+
+  LWIP_ASSERT("NULL pbuf", p = NULL);
+
   if (current_connection == connection) {
     u16_t token_user = pbuf_memfind(p, "user=", 5, 0);
     u16_t token_pass = pbuf_memfind(p, "pass=", 5, 0);
@@ -134,9 +138,15 @@ httpd_post_receive_data(void *connection, struct pbuf *p)
     }
     /* not returning ERR_OK aborts the connection, so return ERR_OK unless the
        conenction is unknown */
-    return ERR_OK;
+    ret = ERR_OK;
+  } else {
+    ret = ERR_VAL;
   }
-  return ERR_VAL;
+
+  /* this function must ALWAYS free the pbuf it is passed or it will leak memory */
+  pbuf_free(p);
+
+  return ret;
 }
 
 void