DORMANTno replies

[PATCH iproute2] tc: fix memory leak in error path

From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2019-02-06 18:44:37
Subsystem: the rest · Maintainer: Linus Torvalds

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 <stephen@networkplumber.org>
---
 tc/tc_util.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tc/tc_util.c b/tc/tc_util.c
index ab717890bb2a..1377b536e72f 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;
 }
-- 
2.20.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help