@@ -235,7 +235,7 @@ err_t lwipClient::recv_callback(struct tcp_pcb* tpcb, struct pbuf* p, err_t err)
235235
236236 if (p == NULL ) {
237237 // Remote host has closed the connection -> close from our side
238- this ->stop ();
238+ this ->close_pcb ();
239239
240240 return ERR_OK;
241241 }
@@ -345,7 +345,7 @@ void lwipClient::flush() {
345345 tcp_output (this ->tcp_info ->pcb );
346346}
347347
348- void lwipClient::stop () {
348+ void lwipClient::close_pcb () {
349349 if (this ->tcp_info ->pcb != nullptr ) {
350350 tcp_recv (this ->tcp_info ->pcb , nullptr );
351351 tcp_sent (this ->tcp_info ->pcb , nullptr );
@@ -360,12 +360,18 @@ void lwipClient::stop() {
360360
361361 // FIXME if err != ERR_OK retry, there may be memory issues, retry?
362362 }
363+ }
363364
365+ void lwipClient::stop () {
366+ this ->close_pcb ();
364367 // reset all the other variables in this class
365368
366- // if(tcp->p != nullptr) {
367- // pbuf_free(tcp->p); // FIXME it happens that a pbuf, with ref == 0 is added for some reason
368- // }
369+ if (this ->tcp_info ->pbuf_head != nullptr ) {
370+ pbuf_free (this ->tcp_info ->pbuf_head ); // FIXME it happens that a pbuf, with ref == 0 is added for some reason
371+ this ->tcp_info ->pbuf_head = nullptr ;
372+ }
373+ this ->tcp_info ->pbuf_offset = 0 ;
374+
369375 if (this ->tcp_info ->server != nullptr ) {
370376 // need to first make the server point to nullptr, then remove the client, can cause infinite recursion
371377 auto server = this ->tcp_info ->server ;
0 commit comments