Simon wrote:
> Mason wrote:
>
>> I tried using the Netconn API because I thought it didn't
>> force a memcpy (is that correct?), but I can't get it to work.
>
> Yes, that's correct. From your example, I guess you're running out of
> netbufs: if netconn_recv returns success, it passes you a netbuf (the RX
> data) and it's up to your application to free the buffer when you're
> done with it.
>
>> struct netconn *conn = netconn_new( NETCONN_TCP );
>> netconn_bind(conn, IP_ADDR_ANY, 44044);
>> netconn_listen(conn);
>> while ( 1 )
>> {
>> struct netconn *foo;
>> netconn_accept(conn,&foo);
>> while ( 1 )
>> {
>> struct netbuf *buf;
>> err = netconn_recv(foo,&buf);
>> if (err) { printf("recv=%d\n", err); break; }
>
> --> Add netbuf_free(buf); here
>
>> }
>> netconn_delete(foo);
>> }
I must be missing something, because it looks like there's a small
memory leak: netconn_recv allocates memory for a struct netbuf
buf = (struct netbuf *)memp_malloc(MEMP_NETBUF);
but netbuf_free does not free this memory
void netbuf_free(struct netbuf *buf)
{
if (buf->p != NULL) { pbuf_free(buf->p); }
buf->p = buf->ptr = NULL;
}
Am I supposed to call netbuf_delete instead?
http://lwip.wikia.com/wiki/Netbuf_delete
void netbuf_delete(struct netbuf *buf)
{
if (buf != NULL) {
if (buf->p != NULL) {
pbuf_free(buf->p);
buf->p = buf->ptr = NULL;
}
memp_free(MEMP_NETBUF, buf);
}
}
--
Regards.
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users