alfred heisner - 2013-04-17

I was experiencing hangs from top on Solaris due to the use of uninitialized memory in the proceeding for loop after that second pread. I used following patch (implements Mike's suggestion), seems to fix things for me too.

*** top-3.8beta1.a/machine/m_sunos5.c Tue May 6 22:41:38 2008
--- top-3.8beta1.b/machine/m_sunos5.c Wed Apr 17 16:47:20 2013
***************
*** 2062,2073 ****
char *p;
int i;

/* 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)
{
op->fd_lpsinfo = fd;
}
--- 2062,2079 ----
char *p;
int i;

/* read the whole file */
p = malloc(st.st_size);
! if (pread(fd, p, st.st_size, 0) < 0)
! {
! (void) close (fd);
! op->fd_lpsinfo = -1;
! continue;
! }

+
/* cache the file descriptor if we can */
if (fd < maxfiles)
{
op->fd_lpsinfo = fd;
}