From: Stephen Hemminger Date: Wed, 6 Feb 2019 18:41:58 +0000 (-0800) Subject: tc: fix memory leak in error path X-Git-Tag: v5.0.0~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d603d55a8160aa40f0a442574f1fc8dedc9a034;p=thirdparty%2Fiproute2.git tc: fix memory leak in error path If value passed to parse_percent was not valid, it would leak the dynamic allocation from sscanf. Fixes: 927e3cfb52b5 ("tc: B.W limits can now be specified in %.") Signed-off-by: Stephen Hemminger --- diff --git a/tc/tc_util.c b/tc/tc_util.c index ab717890b..1377b536e 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -195,7 +195,7 @@ static int parse_percent_rate(char *rate, const char *str, const char *dev) long dev_mbit; int ret; double perc, rate_mbit; - char *str_perc; + char *str_perc = NULL; if (!dev[0]) { fprintf(stderr, "No device specified; specify device to rate limit by percentage\n"); @@ -230,6 +230,7 @@ static int parse_percent_rate(char *rate, const char *str, const char *dev) return 0; malf: + free(str_perc); fprintf(stderr, "Specified rate value could not be read or is malformed\n"); return -1; }