Blob Blame History Raw
diff -Naurp pcp-4.3.2.orig/src/pcp/atop/showgeneric.c pcp-4.3.2/src/pcp/atop/showgeneric.c
--- pcp-4.3.2.orig/src/pcp/atop/showgeneric.c	2019-03-13 15:28:41.000000000 +1100
+++ pcp-4.3.2/src/pcp/atop/showgeneric.c	2020-06-10 08:17:36.748555949 +1000
@@ -336,7 +336,7 @@ generic_samp(double curtime, double nsec
 			move(curline, 0);
 
 			limitedlines();
-			
+
 			curline = prisyst(sstat, curline, nsecs, avgval,
 					fixedhead,  &syssel, &autoorder,
 					maxcpulines, maxdsklines, maxmddlines,
@@ -448,7 +448,7 @@ generic_samp(double curtime, double nsec
 			** one entry per user (list has worst-case size)
 			*/
 			tucumlist = calloc(sizeof(struct tstat),    nproc);
-			ucumlist  = malloc(sizeof(struct tstat *) * nproc);
+			ucumlist  = calloc(sizeof(struct tstat *),  nproc);
 
 			ptrverify(tucumlist,
 			        "Malloc failed for %d ucum procs\n", nproc);
@@ -491,7 +491,7 @@ generic_samp(double curtime, double nsec
 			** one entry per program (list has worst-case size)
 			*/
 			tpcumlist = calloc(sizeof(struct tstat),    nproc);
-			pcumlist  = malloc(sizeof(struct tstat *) * nproc);
+			pcumlist  = calloc(sizeof(struct tstat *),  nproc);
 
 			ptrverify(tpcumlist,
 			        "Malloc failed for %d pcum procs\n", nproc);
@@ -534,7 +534,7 @@ generic_samp(double curtime, double nsec
 			** one entry per user (list has worst-case size)
 			*/
 			tccumlist = calloc(sizeof(struct tstat),    nproc);
-			ccumlist  = malloc(sizeof(struct tstat *) * nproc);
+			ccumlist  = calloc(sizeof(struct tstat *),  nproc);
 
 			ptrverify(tccumlist,
 			        "Malloc failed for %d ccum procs\n", nproc);
@@ -590,7 +590,7 @@ generic_samp(double curtime, double nsec
 			if (sellist)	// remove previous list if needed
 				free(sellist);
 
-			sellist = malloc(sizeof(struct tstat *) * ncurlist);
+			sellist = calloc(sizeof(struct tstat *), ncurlist);
 
 			ptrverify(sellist,
 			       "Malloc failed for %d select ptrs\n", ncurlist);
@@ -672,8 +672,8 @@ generic_samp(double curtime, double nsec
 					if (tsklist)
 						free(tsklist);	// remove current
 
-					tsklist = malloc(sizeof(struct tstat *)
-								    * ntotal);
+					tsklist = calloc(sizeof(struct tstat *),
+								    ntotal);
 
 					ptrverify(tsklist,
 				             "Malloc failed for %d taskptrs\n",
@@ -2023,6 +2023,9 @@ cumusers(struct tstat **curprocs, struct
 	*/
 	for (numusers=i=0; i < numprocs; i++, curprocs++)
 	{
+	        if (*curprocs == NULL)
+		        continue;
+		
 		if (procsuppress(*curprocs, &procsel))
 			continue;
 
@@ -2068,6 +2071,9 @@ cumprogs(struct tstat **curprocs, struct
 	*/
 	for (numprogs=i=0; i < numprocs; i++, curprocs++)
 	{
+	        if (*curprocs == NULL)
+		        continue;
+		
 		if (procsuppress(*curprocs, &procsel))
 			continue;
 
@@ -2111,6 +2117,9 @@ cumconts(struct tstat **curprocs, struct
 	*/
 	for (numconts=i=0; i < numprocs; i++, curprocs++)
 	{
+	        if (*curprocs == NULL)
+		        continue;
+		
 		if (procsuppress(*curprocs, &procsel))
 			continue;
 
diff -Naurp pcp-4.3.2.orig/src/pcp/atop/showlinux.c pcp-4.3.2/src/pcp/atop/showlinux.c
--- pcp-4.3.2.orig/src/pcp/atop/showlinux.c	2020-05-15 10:45:40.904087830 +1000
+++ pcp-4.3.2/src/pcp/atop/showlinux.c	2020-05-19 15:05:03.974494404 +1000
@@ -7,7 +7,7 @@
 ** This source-file contains the Linux-specific functions to calculate
 ** figures to be visualized.
 ** 
-** Copyright (C) 2015,2018,2019 Red Hat.
+** Copyright (C) 2015,2018-2020 Red Hat.
 ** Copyright (C) 2009-2010 JC van Winkel
 ** Copyright (C) 2000-2012 Gerlof Langeveld
 **
@@ -1243,6 +1243,9 @@ priproc(struct tstat **proclist, int fir
         {
                 curstat = *(proclist+i);
 
+                if (curstat == NULL)
+                        continue;
+
                 if (screen && curline >= LINES) /* screen filled entirely ? */
                         break;
 
@@ -2034,10 +2037,17 @@ pridisklike(extraparam *ep, struct perds
 int
 compcpu(const void *a, const void *b)
 {
-        register count_t acpu = (*(struct tstat **)a)->cpu.stime +
-                                (*(struct tstat **)a)->cpu.utime;
-        register count_t bcpu = (*(struct tstat **)b)->cpu.stime +
-                                (*(struct tstat **)b)->cpu.utime;
+        struct tstat	*ta = *(struct tstat **)a;
+        struct tstat	*tb = *(struct tstat **)b;
+
+        register count_t acpu;
+        register count_t bcpu;
+
+        if (ta == NULL)  return 1;
+        if (tb == NULL)  return -1;
+
+        acpu = ta->cpu.stime + ta->cpu.utime;
+        bcpu = tb->cpu.stime + tb->cpu.utime;
 
         if (acpu < bcpu) return  1;
         if (acpu > bcpu) return -1;
@@ -2050,8 +2060,11 @@ compdsk(const void *a, const void *b)
 	struct tstat	*ta = *(struct tstat **)a;
 	struct tstat	*tb = *(struct tstat **)b;
 
-        count_t	adsk;
-        count_t bdsk;
+        register count_t adsk;
+        register count_t bdsk;
+
+	if (ta == NULL)  return  1;
+	if (tb == NULL)  return  -1;
 
 	if (ta->dsk.wsz > ta->dsk.cwsz)
 		adsk = ta->dsk.rio + ta->dsk.wsz - ta->dsk.cwsz;
@@ -2071,8 +2084,17 @@ compdsk(const void *a, const void *b)
 int
 compmem(const void *a, const void *b)
 {
-        register count_t amem = (*(struct tstat **)a)->mem.rmem;
-        register count_t bmem = (*(struct tstat **)b)->mem.rmem;
+	struct tstat	*ta = *(struct tstat **)a;
+	struct tstat	*tb = *(struct tstat **)b;
+
+        register count_t amem;
+        register count_t bmem;
+
+	if (ta == NULL)   return 1;
+	if (tb == NULL)   return -1;
+
+        amem = ta->mem.rmem;
+        bmem = tb->mem.rmem;
 
         if (amem < bmem) return  1;
         if (amem > bmem) return -1;
@@ -2082,12 +2104,25 @@ compmem(const void *a, const void *b)
 int
 compgpu(const void *a, const void *b)
 {
-        register char 	 astate = (*(struct tstat **)a)->gpu.state;
-        register char 	 bstate = (*(struct tstat **)b)->gpu.state;
-        register count_t abusy  = (*(struct tstat **)a)->gpu.gpubusy;
-        register count_t bbusy  = (*(struct tstat **)b)->gpu.gpubusy;
-        register count_t amem   = (*(struct tstat **)a)->gpu.memnow;
-        register count_t bmem   = (*(struct tstat **)b)->gpu.memnow;
+	struct tstat	*ta = *(struct tstat **)a;
+	struct tstat	*tb = *(struct tstat **)b;
+
+        register char 	 astate;
+        register char 	 bstate;
+        register count_t abusy;
+        register count_t bbusy;
+        register count_t amem;
+        register count_t bmem;
+
+	if (ta == NULL)   return 1;
+	if (tb == NULL)   return -1;
+
+        astate = ta->gpu.state;
+        bstate = tb->gpu.state;
+        abusy  = ta->gpu.gpubusy;
+        bbusy  = tb->gpu.gpubusy;
+        amem   = ta->gpu.memnow;
+        bmem   = tb->gpu.memnow;
 
         if (!astate)		// no GPU usage?
 		abusy = amem = -2; 
@@ -2112,14 +2147,17 @@ compgpu(const void *a, const void *b)
 int
 compnet(const void *a, const void *b)
 {
-        register count_t anet = (*(struct tstat **)a)->net.tcpssz +
-                                (*(struct tstat **)a)->net.tcprsz +
-                                (*(struct tstat **)a)->net.udpssz +
-                                (*(struct tstat **)a)->net.udprsz  ;
-        register count_t bnet = (*(struct tstat **)b)->net.tcpssz +
-                                (*(struct tstat **)b)->net.tcprsz +
-                                (*(struct tstat **)b)->net.udpssz +
-                                (*(struct tstat **)b)->net.udprsz  ;
+	struct tstat	*ta = *(struct tstat **)a;
+	struct tstat	*tb = *(struct tstat **)b;
+
+        register count_t anet;
+        register count_t bnet;
+
+	if (ta == NULL)   return 1;
+	if (tb == NULL)   return -1;
+
+        anet = ta->net.tcpssz + ta->net.tcprsz + ta->net.udpssz + ta->net.udprsz;
+        bnet = tb->net.tcpssz + tb->net.tcprsz + tb->net.udpssz + tb->net.udprsz;
 
         if (anet < bnet) return  1;
         if (anet > bnet) return -1;
@@ -2129,8 +2167,17 @@ compnet(const void *a, const void *b)
 int
 compusr(const void *a, const void *b)
 {
-        register int uida = (*(struct tstat **)a)->gen.ruid;
-        register int uidb = (*(struct tstat **)b)->gen.ruid;
+	struct tstat	*ta = *(struct tstat **)a;
+	struct tstat	*tb = *(struct tstat **)b;
+
+        register int     uida;
+        register int     uidb;
+
+	if (ta == NULL)   return 1;
+	if (tb == NULL)   return -1;
+
+        uida = ta->gen.ruid;
+        uidb = tb->gen.ruid;
 
         if (uida > uidb) return  1;
         if (uida < uidb) return -1;
@@ -2140,8 +2187,17 @@ compusr(const void *a, const void *b)
 int
 compnam(const void *a, const void *b)
 {
-        register char *nama = (*(struct tstat **)a)->gen.name;
-        register char *namb = (*(struct tstat **)b)->gen.name;
+	struct tstat	*ta = *(struct tstat **)a;
+	struct tstat	*tb = *(struct tstat **)b;
+
+        register char *nama;
+        register char *namb;
+
+	if (ta == NULL)   return 1;
+	if (tb == NULL)   return -1;
+
+        nama = ta->gen.name;
+        namb = tb->gen.name;
 
         return strcmp(nama, namb);
 }
@@ -2149,10 +2205,19 @@ compnam(const void *a, const void *b)
 int
 compcon(const void *a, const void *b)
 {
-        register char *containera = (*(struct tstat **)a)->gen.container;
-        register char *containerb = (*(struct tstat **)b)->gen.container;
+	struct tstat	*ta = *(struct tstat **)a;
+	struct tstat	*tb = *(struct tstat **)b;
+
+        register char *containera;
+        register char *containerb;
+
+	if (ta == NULL)   return 1;
+	if (tb == NULL)   return -1;
+
+        containera = ta->gen.container;
+        containerb = tb->gen.container;
 
-       return strcmp(containera, containerb);
+        return strcmp(containera, containerb);
 }
 
 /*