ofproto: Do not call ->rule_destruct() if ->rule_construct() failed.
authorBen Pfaff <blp@nicira.com>
Fri, 30 Aug 2013 20:59:37 +0000 (13:59 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 10 Sep 2013 20:02:40 +0000 (13:02 -0700)
Found by inspection.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
ofproto/ofproto.c

index b7f265e..a8634aa 100644 (file)
@@ -199,6 +199,7 @@ static int init_ports(struct ofproto *);
 static void reinit_ports(struct ofproto *);
 
 /* rule. */
+static void ofproto_rule_destroy(struct rule *);
 static void ofproto_rule_destroy__(struct rule *);
 static void ofproto_rule_send_removed(struct rule *, uint8_t reason);
 static bool rule_is_modifiable(const struct rule *);
@@ -2247,18 +2248,24 @@ update_mtu(struct ofproto *p, struct ofport *port)
 }
 \f
 static void
-ofproto_rule_destroy__(struct rule *rule)
+ofproto_rule_destroy(struct rule *rule)
 {
     if (rule) {
         rule->ofproto->ofproto_class->rule_destruct(rule);
-        cls_rule_destroy(&rule->cr);
-        free(rule->ofpacts);
-        ovs_mutex_destroy(&rule->timeout_mutex);
-        ovs_rwlock_destroy(&rule->rwlock);
-        rule->ofproto->ofproto_class->rule_dealloc(rule);
+        ofproto_rule_destroy__(rule);
     }
 }
 
+static void
+ofproto_rule_destroy__(struct rule *rule)
+{
+    cls_rule_destroy(&rule->cr);
+    free(rule->ofpacts);
+    ovs_mutex_destroy(&rule->timeout_mutex);
+    ovs_rwlock_destroy(&rule->rwlock);
+    rule->ofproto->ofproto_class->rule_dealloc(rule);
+}
+
 /* This function allows an ofproto implementation to destroy any rules that
  * remain when its ->destruct() function is called..  This function implements
  * steps 4.4 and 4.5 in the section titled "Rule Life Cycle" in
@@ -5028,13 +5035,13 @@ ofopgroup_complete(struct ofopgroup *group)
             } else {
                 ovs_rwlock_wrlock(&rule->rwlock);
                 oftable_remove_rule(rule);
-                ofproto_rule_destroy__(rule);
+                ofproto_rule_destroy(rule);
             }
             break;
 
         case OFOPERATION_DELETE:
             ovs_assert(!op->error);
-            ofproto_rule_destroy__(rule);
+            ofproto_rule_destroy(rule);
             op->rule = NULL;
             break;