-
Notifications
You must be signed in to change notification settings - Fork 936
Description
I'm still relatively new to Pico and was trying to connect my Pico 2 W to my Wi-Fi so that it could act as a simple remote sensor.
I believe the provided example pico_w/wifi/http_client/example_http_client_util.c
has a memory leak, which prevents it from making more than a few requests before exhausting the allocated protocol control blocks (PCB).
This issue wouldn't have appeared in the provided code as it only makes a few requests before exiting. However, if the example is adapted to a real project, the bug would prevent boards from making more than ~PBUF_POOL_SIZE number of requests.
A pbuf_free(p);
should be added to the receiver function to free the buffer after use. Here is the fixed version:
err_t http_client_receive_print_fn(__unused void *arg, __unused struct altcp_pcb *conn, struct pbuf *p, err_t err) {
HTTP_INFO("\ncontent err %d\n", err);
u16_t offset = 0;
while (offset < p->tot_len) {
char c = (char)pbuf_get_at(p, offset++);
HTTP_INFOC(c);
}
pbuf_free(p);
return ERR_OK;
}
Optionally, it can be added to the internal_recv_fn
function to make it easier to swap in a custom receiver.