[ovs-dev] [overload 1/7] ofproto: Avoid wasting memory malloc()'ing empty action sets for subrules.

Ben Pfaff blp at nicira.com
Fri Oct 1 00:17:35 UTC 2010


GNU libc treats malloc(0) as malloc(1).  Subrules always have an n_actions
of 0, so this code was wasting time and memory for subrules.  This commit
stops doing that.
---
 ofproto/ofproto.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index e571bd4..ee05fdd 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1863,8 +1863,10 @@ rule_create(struct ofproto *ofproto, struct rule *super,
     } else {
         list_init(&rule->list);
     }
-    rule->n_actions = n_actions;
-    rule->actions = xmemdup(actions, n_actions * sizeof *actions);
+    if (n_actions > 0) {
+        rule->n_actions = n_actions;
+        rule->actions = xmemdup(actions, n_actions * sizeof *actions);
+    }
     netflow_flow_clear(&rule->nf_flow);
     netflow_flow_update_time(ofproto->netflow, &rule->nf_flow, rule->created);
 
-- 
1.7.1





More information about the dev mailing list