ofproto: Avoid memory leak in classifier on destruction.
authorBen Pfaff <blp@nicira.com>
Tue, 5 Apr 2011 22:58:06 +0000 (15:58 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 19 Apr 2011 16:32:18 +0000 (09:32 -0700)
ofproto_flush_flows() flushes the flow table but then it reintroduces flows
required by fail-open or in-band.  These are then leaked when the
classifier is destroyed a little later.

This fixes the problem by not reintroducing these flows when ofproto is
being destroyed.

ofproto/ofproto.c

index 0b85e618cb9dbb74e0e1418357cbac8bbb7dd1d1..69639ac942dd14d5ab74ba3c6c8e78d6bbc2c81e 100644 (file)
@@ -326,6 +326,7 @@ static const struct ofhooks default_ofhooks;
 static uint64_t pick_datapath_id(const struct ofproto *);
 static uint64_t pick_fallback_dpid(void);
 
+static void ofproto_flush_flows__(struct ofproto *);
 static int ofproto_expire(struct ofproto *);
 static void flow_push_stats(struct ofproto *, const struct rule *,
                             struct flow *, uint64_t packets, uint64_t bytes,
@@ -691,7 +692,7 @@ ofproto_destroy(struct ofproto *p)
 
     shash_find_and_delete(&all_ofprotos, dpif_name(p->dpif));
 
-    ofproto_flush_flows(p);
+    ofproto_flush_flows__(p);
     connmgr_destroy(p->connmgr);
     classifier_destroy(&p->cls);
     hmap_destroy(&p->facets);
@@ -1000,8 +1001,8 @@ ofproto_delete_flow(struct ofproto *ofproto, const struct cls_rule *target)
     }
 }
 
-void
-ofproto_flush_flows(struct ofproto *ofproto)
+static void
+ofproto_flush_flows__(struct ofproto *ofproto)
 {
     struct facet *facet, *next_facet;
     struct rule *rule, *next_rule;
@@ -1026,6 +1027,12 @@ ofproto_flush_flows(struct ofproto *ofproto)
     }
 
     dpif_flow_flush(ofproto->dpif);
+}
+
+void
+ofproto_flush_flows(struct ofproto *ofproto)
+{
+    ofproto_flush_flows__(ofproto);
     connmgr_flushed(ofproto->connmgr);
 }
 \f