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

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