Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug - Memory leak in Pico W http example #605

Open
cirrith opened this issue Feb 1, 2025 · 1 comment
Open

Bug - Memory leak in Pico W http example #605

cirrith opened this issue Feb 1, 2025 · 1 comment

Comments

@cirrith
Copy link

cirrith commented Feb 1, 2025

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.

@peterharperuk
Copy link
Contributor

Yes, your right. I have a branch somewhere with this fixed. But feel free to raise a PR if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants