As stated by the comment above the structure, the 'action' pointer does not change during the 'dp_netdev_actions' lifetime: we might as well embed the pointed memory into the structure.
The commit also updates the description of dp_netdev_actions_create(). Signed-off-by: Daniele Di Proietto <diproiet...@vmware.com> --- lib/dpif-netdev.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 2cdb2cd..cad063d 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -332,8 +332,8 @@ static int dpif_netdev_flow_from_nlattrs(const struct nlattr *, uint32_t, struct dp_netdev_actions { /* These members are immutable: they do not change during the struct's * lifetime. */ - struct nlattr *actions; /* Sequence of OVS_ACTION_ATTR_* attributes. */ unsigned int size; /* Size of 'actions', in bytes. */ + struct nlattr actions[]; /* Sequence of OVS_ACTION_ATTR_* attributes. */ }; struct dp_netdev_actions *dp_netdev_actions_create(const struct nlattr *, @@ -2432,16 +2432,15 @@ dpif_netdev_queue_to_priority(const struct dpif *dpif OVS_UNUSED, } -/* Creates and returns a new 'struct dp_netdev_actions', with a reference count - * of 1, whose actions are a copy of from the 'ofpacts_len' bytes of - * 'ofpacts'. */ +/* Creates and returns a new 'struct dp_netdev_actions', whose actions are + * a copy of the 'ofpacts_len' bytes of 'ofpacts'. */ struct dp_netdev_actions * dp_netdev_actions_create(const struct nlattr *actions, size_t size) { struct dp_netdev_actions *netdev_actions; - netdev_actions = xmalloc(sizeof *netdev_actions); - netdev_actions->actions = xmemdup(actions, size); + netdev_actions = xmalloc(sizeof *netdev_actions + size); + memcpy(netdev_actions->actions, actions, size); netdev_actions->size = size; return netdev_actions; @@ -2456,7 +2455,6 @@ dp_netdev_flow_get_actions(const struct dp_netdev_flow *flow) static void dp_netdev_actions_free(struct dp_netdev_actions *actions) { - free(actions->actions); free(actions); } -- 2.1.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev