components/top/patches/03.sunos5.patch
author Rich Burridge <rich.burridge@oracle.com>
Wed, 31 Aug 2011 13:46:18 -0700
changeset 506 82fe65b0edf8
parent 361 22214726d642
child 638 d348d0ea7b75
permissions -rw-r--r--
7045172 serious memory leak in top

*** top-3.8beta1/machine/m_sunos5.c.orig	Wed Aug 31 05:23:52 2011
--- top-3.8beta1/machine/m_sunos5.c	Wed Aug 31 05:25:25 2011
***************
*** 2064,2070 ****
  
  	    /* read the whole file */
  	    p = malloc(st.st_size);
! 	    (void)pread(fd, p, st.st_size, 0);
  
  	    /* cache the file descriptor if we can */
  	    if (fd < maxfiles)
--- 2064,2076 ----
  
  	    /* read the whole file */
  	    p = malloc(st.st_size);
! 	    if (pread(fd, p, st.st_size, 0) == -1)
! 	    {
! 		(void) close(fd);
! 		op->fd_psinfo = -1;
! 		free(p);
! 		continue;
! 	    }
  
  	    /* cache the file descriptor if we can */
  	    if (fd < maxfiles)
***************
*** 2148,2154 ****
  		op->oldtime = TIMESPEC_TO_DOUBLE(lwpp->pr_time);
  		op->seen = 1;
  	    }
! 	    free(p);
  	}
  #endif
  
--- 2154,2160 ----
  		op->oldtime = TIMESPEC_TO_DOUBLE(lwpp->pr_time);
  		op->seen = 1;
  	    }
! 	    free(prp);
  	}
  #endif