diff mbox

[ovs-dev] ovs-ofctl: fix memory leak reported by valgrind.

Message ID 1453332778-115544-1-git-send-email-u9012063@gmail.com
State Superseded
Headers show

Commit Message

William Tu Jan. 20, 2016, 11:32 p.m. UTC
Testcase 909: ofproto-dpif - patch ports
The ofpbuf->base is set to OFPBUF_STUB at
    ofputil_decode_switch_features()->ofpbuf_use_const()
so ofpbuf_delete does not free it. Call trace is below:
    vconn_stream_recv(vconn-stream.c:155)
    do_recv(vconn.c:640)
    vconn_recv(vconn.c:598)
    vconn_recv_block(vconn.c:738)
    vconn_recv_xid__(vconn.c:758)
    port_iterator_fetch_features(ovs-ofctl.c:846)
    port_iterator_init(ovs-ofctl.c:889)
    fetch_ofputil_phy_port(ovs-ofctl.c:975)

Signed-off-by: William Tu <u9012063@gmail.com>
---
 utilities/ovs-ofctl.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ben Pfaff Jan. 21, 2016, 12:34 a.m. UTC | #1
On Wed, Jan 20, 2016 at 03:32:58PM -0800, William Tu wrote:
> Testcase 909: ofproto-dpif - patch ports
> The ofpbuf->base is set to OFPBUF_STUB at
>     ofputil_decode_switch_features()->ofpbuf_use_const()
> so ofpbuf_delete does not free it. Call trace is below:
>     vconn_stream_recv(vconn-stream.c:155)
>     do_recv(vconn.c:640)
>     vconn_recv(vconn.c:598)
>     vconn_recv_block(vconn.c:738)
>     vconn_recv_xid__(vconn.c:758)
>     port_iterator_fetch_features(ovs-ofctl.c:846)
>     port_iterator_init(ovs-ofctl.c:889)
>     fetch_ofputil_phy_port(ovs-ofctl.c:975)
> 
> Signed-off-by: William Tu <u9012063@gmail.com>

Thanks for reporting the problem.  I'd prefer a different solution.  I
posted it:
        http://openvswitch.org/pipermail/dev/2016-January/064792.html
diff mbox

Patch

diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 4dbd4ed..8e92160 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -947,6 +947,8 @@  port_iterator_destroy(struct port_iterator *pi)
         }
 
         ofpbuf_delete(pi->reply);
+        /* free because the base of ofpbuf is OFPBUF_STUB. */
+        free(pi->reply->base);
     }
 }