Commit 45104020 authored by Tom Barbette's avatar Tom Barbette

When calling clone(), _data_packet always point to the root of a packet...

When calling clone(), _data_packet always point to the root of a packet cloning chain/tree instead of the packet on which clone() is called. This allows to kill and effectively free intermediate cloned packets in the chain as described in http://librelist.com/browser//click/2014/11/24/clones-of-clones/ .

I use a "while" instead of a "if" to go up to the root and not just the parent _data_packet, if a chain still exists. Normally, if people always use clone() that should not happen, but I'm not sure that all elements do not rely on the possibility of making "chains".
parent 2e137df1
......@@ -654,16 +654,19 @@ Packet::clone()
# endif
if (!p)
return 0;
Packet* origin = this;
while (origin->_data_packet)
origin = origin->_data_packet;
memcpy(p, this, sizeof(Packet));
p->_use_count = 1;
p->_data_packet = this;
p->_data_packet = origin;
# if CLICK_USERLEVEL || CLICK_MINIOS
p->_destructor = 0;
# else
p->_m = m;
# endif
// increment our reference count because of _data_packet reference
_use_count++;
origin->_use_count++;
return p;
#endif /* CLICK_LINUXMODULE */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment