Skip to content

Commit

Permalink
netem: free skb's in tree on reset
Browse files Browse the repository at this point in the history
Netem can leak memory because packets get stored in red-black
tree and it is not cleared on reset.

Reported by: Сергеев Сергей <adron@yapic.net>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
stephen hemminger authored and David S. Miller committed Oct 11, 2013
1 parent 638a52b commit ff70405
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions net/sched/sch_netem.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,21 @@ static psched_time_t packet_len_2_sched_time(unsigned int len, struct netem_sche
return PSCHED_NS2TICKS(ticks);
}

static void tfifo_reset(struct Qdisc *sch)
{
struct netem_sched_data *q = qdisc_priv(sch);
struct rb_node *p;

while ((p = rb_first(&q->t_root))) {
struct sk_buff *skb = netem_rb_to_skb(p);

rb_erase(p, &q->t_root);
skb->next = NULL;
skb->prev = NULL;
kfree_skb(skb);
}
}

static void tfifo_enqueue(struct sk_buff *nskb, struct Qdisc *sch)
{
struct netem_sched_data *q = qdisc_priv(sch);
Expand Down Expand Up @@ -610,6 +625,7 @@ static void netem_reset(struct Qdisc *sch)
struct netem_sched_data *q = qdisc_priv(sch);

qdisc_reset_queue(sch);
tfifo_reset(sch);
if (q->qdisc)
qdisc_reset(q->qdisc);
qdisc_watchdog_cancel(&q->watchdog);
Expand Down

0 comments on commit ff70405

Please sign in to comment.