Jan Rybar 24b2b8
commit a1bc3bf207c64e2a26d8a7a3c20dd960e0e5c545
Jan Rybar 24b2b8
Author: Jan Rybar <jrybar@redhat.com>
Jan Rybar 24b2b8
Date:   Thu May 6 16:30:54 2021 +0200
Jan Rybar 24b2b8
Jan Rybar 24b2b8
    Coverity scan findings - memleaks, unused vars, potential nullptr dereferences
Jan Rybar 24b2b8
Jan Rybar 24b2b8
diff --git a/lib/test_process.c b/lib/test_process.c
Jan Rybar 24b2b8
index e20b270d..f8ff5ed0 100644
Jan Rybar 24b2b8
--- a/lib/test_process.c
Jan Rybar 24b2b8
+++ b/lib/test_process.c
Jan Rybar 24b2b8
@@ -69,6 +69,7 @@ signal_handler(int signum, siginfo_t *siginfo, void *ucontext)
Jan Rybar 24b2b8
 	    exit(EXIT_FAILURE);
Jan Rybar 24b2b8
     }
Jan Rybar 24b2b8
 
Jan Rybar 24b2b8
+    free(signame);
Jan Rybar 24b2b8
 }
Jan Rybar 24b2b8
 
Jan Rybar 24b2b8
 int main(int argc, char *argv[])
Jan Rybar 24b2b8
diff --git a/pmap.c b/pmap.c
Jan Rybar 24b2b8
index 49a2a6a8..d8565fc3 100644
Jan Rybar 24b2b8
--- a/pmap.c
Jan Rybar 24b2b8
+++ b/pmap.c
Jan Rybar 24b2b8
@@ -346,6 +346,9 @@ static void print_extended_maps (FILE *f)
Jan Rybar 24b2b8
 			if (listnode == NULL) {
Jan Rybar 24b2b8
 				assert(firstmapping == 2);
Jan Rybar 24b2b8
 				listnode = calloc(1, sizeof *listnode);
Jan Rybar 24b2b8
+				if (listnode == NULL)
Jan Rybar 24b2b8
+					xerrx(EXIT_FAILURE, _("ERROR: memory allocation failed"));
Jan Rybar 24b2b8
+
Jan Rybar 24b2b8
 				if (listhead == NULL) {
Jan Rybar 24b2b8
 					assert(listtail == NULL);
Jan Rybar 24b2b8
 					listhead = listnode;
Jan Rybar 24b2b8
diff --git a/watch.c b/watch.c
Jan Rybar 24b2b8
index 1a95454e..772879cd 100644
Jan Rybar 24b2b8
--- a/watch.c
Jan Rybar 24b2b8
+++ b/watch.c
Jan Rybar 24b2b8
@@ -124,8 +124,6 @@ static void reset_ansi(void)
Jan Rybar 24b2b8
 
Jan Rybar 24b2b8
 static void init_ansi_colors(void)
Jan Rybar 24b2b8
 {
Jan Rybar 24b2b8
-	int color;
Jan Rybar 24b2b8
-
Jan Rybar 24b2b8
 	short ncurses_colors[] = {
Jan Rybar 24b2b8
 		-1, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW,
Jan Rybar 24b2b8
 		COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE
Jan Rybar 24b2b8
@@ -172,6 +170,9 @@ static int process_ansi_color_escape_sequence(char** escape_sequence) {
Jan Rybar 24b2b8
 	// ESC[ 48;2;⟨r⟩;⟨g⟩;⟨b⟩ m Select RGB background color
Jan Rybar 24b2b8
 	int num;
Jan Rybar 24b2b8
 
Jan Rybar 24b2b8
+	if (!escape_sequence)
Jan Rybar 24b2b8
+		return 0; /* avoid NULLPTR dereference, return "not understood" */
Jan Rybar 24b2b8
+
Jan Rybar 24b2b8
 	if ((*escape_sequence)[0] != ';')
Jan Rybar 24b2b8
 		return 0; /* not understood */
Jan Rybar 24b2b8