lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Problems freeing a packet buffer using pbuf_free


From: Dance, Brian
Subject: Re: [lwip-users] Problems freeing a packet buffer using pbuf_free
Date: Wed, 20 Jun 2012 13:49:05 +0100

Does the rx packet that you copy from get freed somewhere else?


From: address@hidden [mailto:address@hidden On Behalf Of Justin Drake
Sent: 18 June 2012 15:31
To: address@hidden
Subject: [lwip-users] Problems freeing a packet buffer using pbuf_free

I am a function to send data packets. Each time a packet is receive, I create a buffer using `pbuf_alloc`. I then send the packet using `upd_sendto`. Finally, I free the buffer with `pbuf_free`.

For some reason, `pbuf_free` is not freeing the buffers. (I get a buffer overflow after `n` packets, where `n` is the pool size.)

How can I have `pbuf_free` actually free my buffers? How is the buffer overflow avoided?

Below is my implementation:

static err_t IAP_tftp_send_data_packet(struct udp_pcb *upcb, struct ip_addr *to, int to_port, int block)
{
  err_t err
;
 
struct pbuf *pkt_buf;
 
char packet[TFTP_DATA_PKT_LEN_MAX];
 
int bytesRead;
 
int bytesToSend;

 
/* Specify that we are sending data. */
  IAP_tftp_set_opcode
(packet, TFTP_DATA);

 
/* Specify the block number that we are sending. */
  IAP_tftp_set_block
(packet, block);

  bytesRead
= IAP_tftp_set_data(packet, block);

 
if(bytesRead != 0) {
    bytesToSend
= TFTP_DATA_PKT_LEN_MAX - (512 - bytesRead + 1);
 
} else {
    bytesToSend
= TFTP_DATA_PKT_LEN_MAX - 512;
 
}

  pkt_buf
= pbuf_alloc(PBUF_TRANSPORT, bytesToSend, PBUF_POOL);

 
if (!pkt_buf)
 
{
    print
("(TFTP) Buffer overflow!\r\n");
 
}

 
/* Copy the file data onto pkt_buf. */
  memcpy
(pkt_buf->payload, packet, bytesToSend);

  err
= udp_sendto(upcb, pkt_buf, to, to_port);

 
/* free the buffer pbuf */
  printf
("%d\n\r", pbuf_free(pkt_buf));

 
return err;
}

**********************************************************************
This e-mail is from Ultra Electronics Limited and any attachments to it are confidential to the
intendedĀ  recipient and may also be privileged. If you have received it in error please notify the
sender and deleteĀ it from your system. If you are not the intended recipient you must not copy
it or use it for any purpose nor disclose or distribute its contents to any other person.

All communications may be subject to interception or monitoring for operational and/or security purposes.
Please rely on your own virus checking as the sender cannot accept any liability for any damage arising
from any bug or virus infection. Ultra Electronics Limited is a company registered in England and Wales,
registration number 2830644. The address of its registered office is 417 Bridport Road, Greenford,
Middlesex, UB6 8UA.

**********************************************************************


reply via email to

[Prev in Thread] Current Thread [Next in Thread]