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