ofctl_parse_target: Fix memory leaks if there is no usable protocol
When there is no usable protocol, ofctl_parse_flows__ returns without
properly freeing memory. A previous patch failed to fix this issue.
This patch fixes it.
Reported-at:
Reported-at:
@@ -22,7 +22,7 @@ ofctl_parse_flows__(struct ofputil_flow_mod *fms, size_t n_fms,
if (!(usable_protocols & OFPUTIL_P_ANY)) {
printf("no usable protocol\n");
- return;
+ goto free;
}
for (i = 0; i < sizeof(enum ofputil_protocol) * CHAR_BIT; i++) {
protocol = 1u << i;
@@ -40,7 +40,11 @@ ofctl_parse_flows__(struct ofputil_flow_mod *fms, size_t n_fms,
msg = ofputil_encode_flow_mod(fm, protocol);
ofpbuf_delete(msg);
+ }
+free:
+ for (i = 0; i < n_fms; i++) {
+ struct ofputil_flow_mod *fm = &fms[i];
free(CONST_CAST(struct ofpact *, fm->ofpacts));
minimatch_destroy(&fm->match);
}
@@ -62,7 +66,6 @@ ofctl_parse_flow(const char *input, int command)
free(error);
} else {
ofctl_parse_flows__(&fm, 1, usable_protocols);
- minimatch_destroy(&fm.match);
}
}
