All of the pool_get(mypool, new_elt) variants are capable of expanding - and 
hence moving - mypool, leading to dangling references to free memory if you’re 
not careful. Here’s the usual coding pattern:

old_elt = pool_elt_at_index (mypool, index);

/* use old-elt */

pool_get (mypool, new_elt);

/* old-elt now INVALID, but index (or p[0]) is still fine */

old_elt = pool_elt_at_index (mypool, index);

<do whatever, old_elt and new_elt are both good-to-go >

Thanks… Dave

From: vpp-dev-boun...@lists.fd.io [mailto:vpp-dev-boun...@lists.fd.io] On 
Behalf Of ???
Sent: Thursday, January 4, 2018 1:22 AM
To: vpp-dev <vpp-dev@lists.fd.io>
Subject: [vpp-dev] 'pool_elt_at_index' Relative Addressing Cause a Mistake


Hi guys,

I'm testing ikev2. When I initiate a sa succeed(pr1), then add the other one 
(pr2), the sa->pr1->name is rewritten.

After viewing I find the 'pool_elt_at_index' is relative addressing . And the 
'pool_base' may change when use the pointer we preserved before.

eg:'pool_elt_at_index (km->profiles, p[0]);'

How can we solve the problem?

Thanks,
Xyxue
________________________________
_______________________________________________
vpp-dev mailing list
vpp-dev@lists.fd.io
https://lists.fd.io/mailman/listinfo/vpp-dev

Reply via email to