I have a question about pool buffer management.
Let's say that a function creates, initializes, and then registers a fifo for a UDP port.
The function then waits for incoming packets. Several packets arrive and are placed in
the fifo. The function removes one that it needed, with other packets still remaining
in the fifo. If the function then returns, without emptying the fifo, what happens to
the pool buffers containing the rest of the packets that were still linked in the fifo list
when the fifo goes away ?
Pool buffers in Fifos
Re: Pool buffers in Fifos
Are you unregistering the fifo before you exit?
Re: Pool buffers in Fifos
Are you unregistering the fifo before you exit?
Yes. But unregistering doesn't empty the fifo. It only breaks the
association with a port.
Yes. But unregistering doesn't empty the fifo. It only breaks the
association with a port.
Re: Pool buffers in Fifos
It's a c++ object, so maybe the fifo is freed when the destructor is called?
Re: Pool buffers in Fifos
Are you talking about OS_FIFIO? I'm pretty sure that's written in C. If you are allocating structures inside your function on the stack, then when your function exits your structures are released. If you're allocating your structures on the heap then you have to release them yourself. If you don't, then I would suspect that when your function exits you leak the memory.
Re: Pool buffers in Fifos
It's a c++ object, so maybe the fifo is freed when the destructor is called?
The netburner code shows fifos as a struct. Also OSFifoInit must be called explicitly
(instead of being included in a constructor), so I think it's a C object.
Are you talking about OS_FIFIO? I'm pretty sure that's written in C. If you are allocating structures inside your function on the stack, then when your function exits your structures are released.
Yes it is allocated on the stack just like several of netburner's examples. When the
function exits, the fifo is freed. However, notice what is freed:
typedef struct os_fifo {
OS_FIFO_EL *pHead;
OS_FIFO_EL *pTail;
BYTE OSFifoGrp;
BYTE OSFifoTbl[8];
} OS_FIFO;
Assuming that there is no smart destructor (and I cannot find a constructor nor a
destructor in the netburner code) then the fifo elements which are pool buffers in
this case (UDP packets) are lost.
In most of the netburner code, there is no concern about any (additional) packets
that may have arrived and were placed in the fifo but not used (removed from the
fifo). The only exception that I've seen is the code for the TFTP client (GetTFTP and
SendTFTP), where the fifo is explicitly emptied after unregistering the fifo.
It makes one wonder if this kind of code should always be included between
unregistering the fifo and freeing the fifo.
The netburner code shows fifos as a struct. Also OSFifoInit must be called explicitly
(instead of being included in a constructor), so I think it's a C object.
Are you talking about OS_FIFIO? I'm pretty sure that's written in C. If you are allocating structures inside your function on the stack, then when your function exits your structures are released.
Yes it is allocated on the stack just like several of netburner's examples. When the
function exits, the fifo is freed. However, notice what is freed:
typedef struct os_fifo {
OS_FIFO_EL *pHead;
OS_FIFO_EL *pTail;
BYTE OSFifoGrp;
BYTE OSFifoTbl[8];
} OS_FIFO;
Assuming that there is no smart destructor (and I cannot find a constructor nor a
destructor in the netburner code) then the fifo elements which are pool buffers in
this case (UDP packets) are lost.
In most of the netburner code, there is no concern about any (additional) packets
that may have arrived and were placed in the fifo but not used (removed from the
fifo). The only exception that I've seen is the code for the TFTP client (GetTFTP and
SendTFTP), where the fifo is explicitly emptied after unregistering the fifo.
It makes one wonder if this kind of code should always be included between
unregistering the fifo and freeing the fifo.
Re: Pool buffers in Fifos
Maybe if you showed your actual code this would make more sense to me. When I deal with ethernet buffers the first thing I do is read the data in a buffer that I own (a side-effect is the buffer is immediately freed for resuse). I'm not sure what the pool buffers even have to do with this question unless you're somehow using the underlying pool buffer pointers directly. Can you post the function?
Re: Pool buffers in Fifos
You must empty the fifo or it is a buffer leak that will eventually kill the system
After you unregister the fifo (To make sure no new packets sneak in while you are unregistering)
Then
do
{
PoolPtr pp= (PoolPtr) OSFifoPendNoWait( &TheFifo);
if(pp!=NULL) FreeBuffer(pp);
}
while (pp!=NULL);
After you unregister the fifo (To make sure no new packets sneak in while you are unregistering)
Then
do
{
PoolPtr pp= (PoolPtr) OSFifoPendNoWait( &TheFifo);
if(pp!=NULL) FreeBuffer(pp);
}
while (pp!=NULL);