Blame SOURCES/openscap-1.3.4-fix_memory_leak_probe-file-PR_1594.patch

8b65ee
From 2c270e796ecc82567f5533bf1da35100b6eb4ee3 Mon Sep 17 00:00:00 2001
8b65ee
From: Evgeny Kolesnikov <ekolesni@redhat.com>
8b65ee
Date: Mon, 7 Sep 2020 08:03:38 +0200
8b65ee
Subject: [PATCH] Fix memory leak
8b65ee
8b65ee
It seems that `SEXP_listref_first` result is not a good candidate
8b65ee
to be (re)placed into a list.
8b65ee
---
8b65ee
 src/OVAL/probes/probe-api.c | 29 +++++++++++++----------------
8b65ee
 1 file changed, 13 insertions(+), 16 deletions(-)
8b65ee
8b65ee
diff --git a/src/OVAL/probes/probe-api.c b/src/OVAL/probes/probe-api.c
8b65ee
index 3bae38ebc..417138c3b 100644
8b65ee
--- a/src/OVAL/probes/probe-api.c
8b65ee
+++ b/src/OVAL/probes/probe-api.c
8b65ee
@@ -130,6 +130,11 @@ SEXP_t *probe_item_attr_add(SEXP_t * item, const char *name, SEXP_t * val)
8b65ee
 {
8b65ee
 	SEXP_t *n_ref, *ns;
8b65ee
 
8b65ee
+	if (val == NULL)
8b65ee
+		ns = SEXP_string_new(name, strlen(name));
8b65ee
+	else
8b65ee
+		ns = SEXP_string_newf(":%s", name);
8b65ee
+
8b65ee
 	n_ref = SEXP_listref_first(item);
8b65ee
 
8b65ee
 	if (SEXP_listp(n_ref)) {
8b65ee
@@ -137,13 +142,7 @@ SEXP_t *probe_item_attr_add(SEXP_t * item, const char *name, SEXP_t * val)
8b65ee
 		 * There are already some attributes.
8b65ee
 		 * Just add the new to the list.
8b65ee
 		 */
8b65ee
-		if (val == NULL)
8b65ee
-			ns = SEXP_string_new(name, strlen(name));
8b65ee
-		else
8b65ee
-			ns = SEXP_string_newf(":%s", name);
8b65ee
-
8b65ee
 		SEXP_list_add(n_ref, ns);
8b65ee
-		SEXP_free(ns);
8b65ee
 
8b65ee
 		if (val != NULL)
8b65ee
 			SEXP_list_add(n_ref, val);
8b65ee
@@ -155,23 +154,21 @@ SEXP_t *probe_item_attr_add(SEXP_t * item, const char *name, SEXP_t * val)
8b65ee
 		 * S-exp and the attribute.
8b65ee
 		 */
8b65ee
 		SEXP_t *nl;
8b65ee
+		SEXP_t *x_ref;
8b65ee
 
8b65ee
-		if (val == NULL)
8b65ee
-			ns = SEXP_string_new(name, strlen(name));
8b65ee
-		else
8b65ee
-			ns = SEXP_string_newf(":%s", name);
8b65ee
-
8b65ee
-		nl = SEXP_list_new(n_ref, ns, val, NULL);
8b65ee
+		x_ref = SEXP_list_nth(item, 1);
8b65ee
+		nl = SEXP_list_new(x_ref, ns, val, NULL);
8b65ee
+		SEXP_free(x_ref);
8b65ee
 
8b65ee
-		SEXP_free(n_ref);
8b65ee
-		SEXP_free(ns);
8b65ee
-
8b65ee
-		n_ref = SEXP_list_replace(item, 1, nl);
8b65ee
+		x_ref = SEXP_list_replace(item, 1, nl);
8b65ee
+		SEXP_free(x_ref);
8b65ee
 		SEXP_free(nl);
8b65ee
 	}
8b65ee
 
8b65ee
 	SEXP_free(n_ref);
8b65ee
 
8b65ee
+	SEXP_free(ns);
8b65ee
+
8b65ee
 	return (val);
8b65ee
 }
8b65ee