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

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