[ovs-dev] [leaks 1/3] ofproto-dpif: Fix memory leak in port_dump_next().
Ethan Jackson
ethan at nicira.com
Fri Jan 25 23:11:22 UTC 2013
Acked-by: Ethan Jackson <ethan at nicira.com>
On Thu, Jan 24, 2013 at 3:20 PM, Ben Pfaff <blp at nicira.com> wrote:
> The caller of port_query_by_name() is responsible for freeing the
> ofproto_port that it returns on success, but ofproto-dpif did not do this.
>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
> ofproto/ofproto-dpif.c | 20 ++++++++++++++++++--
> 1 files changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
> index d75a63c..411795a 100644
> --- a/ofproto/ofproto-dpif.c
> +++ b/ofproto/ofproto-dpif.c
> @@ -1561,8 +1561,10 @@ port_construct(struct ofport *port_)
> if (odp_port_to_ofp_port(ofproto, port->odp_port) != OFPP_NONE) {
> VLOG_ERR("port %s already has an OpenFlow port number\n",
> dpif_port.name);
> + dpif_port_destroy(&dpif_port);
> return EBUSY;
> }
> + dpif_port_destroy(&dpif_port);
>
> hmap_insert(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node,
> hash_int(port->odp_port, 0));
> @@ -3058,6 +3060,9 @@ struct port_dump_state {
> uint32_t bucket;
> uint32_t offset;
> bool ghost;
> +
> + struct ofproto_port port;
> + bool has_port;
> };
>
> static int
> @@ -3076,12 +3081,20 @@ port_dump_next(const struct ofproto *ofproto_ OVS_UNUSED, void *state_,
> const struct sset *sset;
> struct sset_node *node;
>
> + if (state->has_port) {
> + ofproto_port_destroy(&state->port);
> + state->has_port = false;
> + }
> sset = state->ghost ? &ofproto->ghost_ports : &ofproto->ports;
> while ((node = sset_at_position(sset, &state->bucket, &state->offset))) {
> int error;
>
> - error = port_query_by_name(ofproto_, node->name, port);
> - if (error != ENODEV) {
> + error = port_query_by_name(ofproto_, node->name, &state->port);
> + if (!error) {
> + *port = state->port;
> + state->has_port = true;
> + return 0;
> + } else if (error != ENODEV) {
> return error;
> }
> }
> @@ -3101,6 +3114,9 @@ port_dump_done(const struct ofproto *ofproto_ OVS_UNUSED, void *state_)
> {
> struct port_dump_state *state = state_;
>
> + if (state->has_port) {
> + ofproto_port_destroy(&state->port);
> + }
> free(state);
> return 0;
> }
> --
> 1.7.2.5
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
More information about the dev
mailing list