summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-01-16 06:23:51 (GMT)
committerThomas Haller <thaller@redhat.com>2018-01-16 06:26:50 (GMT)
commit76e5399dab25969e2e2513450aa800f8841d5b89 (patch)
tree93c654925444fb9f6746165ff8708573227675ad /lib
parent22f8e867bac80b8c2e0cd16165e0844bdd3d618b (diff)
downloadlibnl-76e5399dab25969e2e2513450aa800f8841d5b89.zip
libnl-76e5399dab25969e2e2513450aa800f8841d5b89.tar.gz
libnl-76e5399dab25969e2e2513450aa800f8841d5b89.tar.bz2
route: free previous data in rtnl_netem_set_delay_distribution_data()
Otherwise, calling rtnl_netem_set_delay_distribution_data() will leak memory, and that should just be supported. Also, handle failure to allocate memory.
Diffstat (limited to 'lib')
-rw-r--r--lib/route/qdisc/netem.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/route/qdisc/netem.c b/lib/route/qdisc/netem.c
index 05c2eb9..b0ee2a6 100644
--- a/lib/route/qdisc/netem.c
+++ b/lib/route/qdisc/netem.c
@@ -873,6 +873,7 @@ int rtnl_netem_get_delay_distribution(struct rtnl_qdisc *qdisc, int16_t **dist_p
*/
int rtnl_netem_set_delay_distribution_data(struct rtnl_qdisc *qdisc, const int16_t *data, size_t len) {
struct rtnl_netem *netem;
+ int16_t *new_data;
if (!(netem = rtnl_tc_data(TC_CAST(qdisc))))
BUG();
@@ -880,7 +881,12 @@ int rtnl_netem_set_delay_distribution_data(struct rtnl_qdisc *qdisc, const int16
if (len > MAXDIST)
return -NLE_INVAL;
- netem->qnm_dist.dist_data = (int16_t *) calloc(len, sizeof(int16_t));
+ new_data = (int16_t *) calloc(len, sizeof(int16_t));
+ if (!new_data)
+ return -NLE_NOMEM;
+
+ free (netem->qnm_dist.dist_data);
+ netem->qnm_dist.dist_data = new_data;
memcpy(netem->qnm_dist.dist_data, data, len * sizeof(int16_t));