From 289dc3a077f05fba93816fbdfbbfe032322d7f64 Mon Sep 17 00:00:00 2001
From: Steve Grubb <ausearch.1@gmail.com>
Date: Tue, 21 May 2024 12:28:29 -0400
Subject: [PATCH] Fix memory leaks

Conflict:NA
Reference:https://github.com/linux-audit/audit-userspace/commit/289dc3a077f05fba93816fbdfbbfe032322d7f64

---
 src/auditd-listen.c  | 2 +-
 src/ausearch-lol.c   | 2 ++
 src/ausearch-parse.c | 6 ++++--
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/auditd-listen.c b/src/auditd-listen.c
index ea3f137c..52076361 100644
--- a/src/auditd-listen.c
+++ b/src/auditd-listen.c
@@ -443,8 +443,8 @@ static int negotiate_credentials(ev_tcp *io)
 				gss_release_name(&min_stat, &client);
 				return -1;
 			}
-			gss_release_buffer(&min_stat, &send_tok);
 		}
+		gss_release_buffer(&min_stat, &send_tok);
 	} while (maj_stat == GSS_S_CONTINUE_NEEDED);
 
 	maj_stat = gss_display_name(&min_stat, client, &recv_tok, NULL);
diff --git a/src/ausearch-lol.c b/src/ausearch-lol.c
index a5418079..784c58f6 100644
--- a/src/ausearch-lol.c
+++ b/src/ausearch-lol.c
@@ -311,6 +311,7 @@ int lol_add_record(lol *lo, char *buff)
 	n.type = e.type;
 	n.message = strdup(buff);
 	if(n.message == NULL) {
+		free((char *)e.node);
 		fprintf(stderr, "Out of memory. Check %s file, %d line", __FILE__, __LINE__);
 		return 0;
 	}
@@ -369,6 +370,7 @@ int lol_add_record(lol *lo, char *buff)
 	// Create new event and fill it in
 	l = malloc(sizeof(llist));
 	if (l == NULL) {
+		free((char *)e.node);
 		fprintf(stderr, "Out of memory. Check %s file, %d line", __FILE__, __LINE__);
 		return 0;
 	}
diff --git a/src/ausearch-parse.c b/src/ausearch-parse.c
index be57606b..4c9bef0d 100644
--- a/src/ausearch-parse.c
+++ b/src/ausearch-parse.c
@@ -769,9 +769,11 @@ static int common_path_parser(search_items *s, char *path)
 			if ((sn.str[0] == '.') && ((sn.str[1] == '.') ||
 				(sn.str[1] == '/')) && s->cwd) {
 				char *tmp = malloc(PATH_MAX);
-				if (tmp == NULL)
+				if (tmp == NULL) {
+					free(sn.str);
 					return 6;
-				snprintf(tmp, PATH_MAX, "%s/%s", 
+				}
+				snprintf(tmp, PATH_MAX, "%s/%s",
 					s->cwd, sn.str);
 				free(sn.str);
 				sn.str = tmp;
-- 
2.33.0

