ofp-util: Make decoding switch features harder to misuse (and fix leak).
authorBen Pfaff <blp@ovn.org>
Thu, 21 Jan 2016 00:33:13 +0000 (16:33 -0800)
committerBen Pfaff <blp@ovn.org>
Thu, 21 Jan 2016 05:53:22 +0000 (21:53 -0800)
commit667bb1fbf97774cc0627eeca9972c4f8d219fe54
tree22eee119dc87cb5547a61d8f866faa17d50df24b
parent808c73b4dd043c131b216ace99b89b08f45910b4
ofp-util: Make decoding switch features harder to misuse (and fix leak).

Until now, ofputil_decode_switch_features() has put the ports from the
switch features message into a separate ofpbuf supplied as an argument.
The natural desire for a caller is to just reuse an ofpbuf that it already
has, and that's what one of the callers did.  This however has the
nonobvious effect of leaking the memory that the ofpbuf previously owned,
since it gets replaced by an OFPBUF_CONST-type ofpbuf.

This commit avoids the problem by changing the interface to pull the
header from an ofpbuf that the caller already has.

This fixes a leak in testcase 909 "ofproto-dpif - patch ports".

Found by valgrind.

Reported-by: William Tu <u9012063@gmail.com>
Reported-at: http://openvswitch.org/pipermail/dev/2016-January/064771.html
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Andy Zhou <azhou@ovn.org>
lib/learning-switch.c
lib/ofp-print.c
lib/ofp-util.c
lib/ofp-util.h
utilities/ovs-ofctl.c