Blame SOURCES/0018-fix-memory-leaks-in-do_sfeatures.patch

4f6fcd
From 78b5b29e6cf286ce687e7b4d42745fb06cfb2353 Mon Sep 17 00:00:00 2001
4f6fcd
From: Ivan Vecera <ivecera@redhat.com>
4f6fcd
Date: Fri, 25 Sep 2020 08:39:16 +0200
4f6fcd
Subject: [PATCH 18/19] fix memory leaks in do_sfeatures()
4f6fcd
4f6fcd
Memory blocks referenced by new_state and old_state are never freed.
4f6fcd
For efeatures there is no need to check pointer as free() can be called
4f6fcd
with NULL parameter.
4f6fcd
4f6fcd
Fixes: 6042804cf6ec ("Change -k/-K options to use ETHTOOL_{G,S}FEATURES")
4f6fcd
4f6fcd
Cc: Michal Kubecek <mkubecek@suse.cz>
4f6fcd
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
4f6fcd
---
4f6fcd
 ethtool.c | 13 +++++++------
4f6fcd
 1 file changed, 7 insertions(+), 6 deletions(-)
4f6fcd
4f6fcd
diff --git a/ethtool.c b/ethtool.c
4f6fcd
index 2e24e98187d2..32ef80add923 100644
4f6fcd
--- a/ethtool.c
4f6fcd
+++ b/ethtool.c
4f6fcd
@@ -2392,9 +2392,10 @@ static int do_sfeatures(struct cmd_context *ctx)
4f6fcd
 	int any_changed = 0, any_mismatch = 0;
4f6fcd
 	u32 off_flags_wanted = 0;
4f6fcd
 	u32 off_flags_mask = 0;
4f6fcd
-	struct ethtool_sfeatures *efeatures;
4f6fcd
+	struct ethtool_sfeatures *efeatures = NULL;
4f6fcd
+	struct feature_state *old_state = NULL;
4f6fcd
+	struct feature_state *new_state = NULL;
4f6fcd
 	struct cmdline_info *cmdline_features;
4f6fcd
-	struct feature_state *old_state, *new_state;
4f6fcd
 	struct ethtool_value eval;
4f6fcd
 	unsigned int i, j;
4f6fcd
 	int err, rc;
4f6fcd
@@ -2418,8 +2419,6 @@ static int do_sfeatures(struct cmd_context *ctx)
4f6fcd
 		memset(efeatures->features, 0,
4f6fcd
 		       FEATURE_BITS_TO_BLOCKS(defs->n_features) *
4f6fcd
 		       sizeof(efeatures->features[0]));
4f6fcd
-	} else {
4f6fcd
-		efeatures = NULL;
4f6fcd
 	}
4f6fcd
 
4f6fcd
 	/* Generate cmdline_info for legacy flags and kernel-named
4f6fcd
@@ -2578,9 +2577,11 @@ static int do_sfeatures(struct cmd_context *ctx)
4f6fcd
 	rc = 0;
4f6fcd
 
4f6fcd
 err:
4f6fcd
+	free(new_state);
4f6fcd
+	free(old_state);
4f6fcd
 	free(defs);
4f6fcd
-	if (efeatures)
4f6fcd
-		free(efeatures);
4f6fcd
+	free(efeatures);
4f6fcd
+
4f6fcd
 	return rc;
4f6fcd
 }
4f6fcd
 
4f6fcd
-- 
4f6fcd
2.26.2
4f6fcd