diff --git a/lib/dialects/darwin/dlsof.h b/lib/dialects/darwin/dlsof.h index 48ad413b..7f5841f0 100644 --- a/lib/dialects/darwin/dlsof.h +++ b/lib/dialects/darwin/dlsof.h @@ -136,7 +136,7 @@ struct lsof_context_dialect { int nb_fds; /* bytes allocated to FDs */ # if DARWINV >= 900 - int nb_threads; /* Threads bytes allocated */ + int n_threads; /* Threads entries allocated */ uint64_t *threads; /* Thread buffer */ # endif /* DARWINV>=900 */ @@ -161,7 +161,7 @@ struct lsof_context_dialect { # if DARWINV >= 900 # define Threads (ctx->dialect.threads) -# define NbThreads (ctx->dialect.nb_threads) +# define NThreads (ctx->dialect.n_threads) # endif /* DARWINV>=900 */ # if defined(PROC_PIDLISTFILEPORTS) diff --git a/lib/dialects/darwin/dproc.c b/lib/dialects/darwin/dproc.c index 8b3ea2c3..3f4e90f1 100644 --- a/lib/dialects/darwin/dproc.c +++ b/lib/dialects/darwin/dproc.c @@ -46,10 +46,6 @@ static char copyright[] = "@(#) Copyright 2005-2007 Apple Inc. and Purdue " #define PIDS_INCR (sizeof(int) * 32) /* PID space increment */ #define VIPS_INCR 16 /* Vips space increment */ -#if DARWINV >= 900 -# define THREADS_INCR (sizeof(uint64_t) * 32) /* Threads space increment */ -#endif /* DARWINV>=900 */ - #if defined(PROC_PIDLISTFILEPORTS) # define FILEPORTS_INCR \ (sizeof(struct proc_fileportinfo) * 32) /* Fileports space increment \ @@ -692,30 +688,24 @@ static void process_threads(struct lsof_context *ctx, /* context */ int pid, /* PID */ uint32_t n) /* number of threads */ { - int i, nb, nt; + int i, nb, need, nt; /* * Make sure a thread buffer has been allocated. */ - n += 10; - if (n > NbThreads) { - while (n > NbThreads) { - NbThreads += THREADS_INCR; - } - if (!Threads) - Threads = (uint64_t *)malloc((MALLOC_S)NbThreads); - else - Threads = - (uint64_t *)realloc((MALLOC_P *)Threads, (MALLOC_S)NbThreads); - if (!Threads) { + need = (int)n + 10; + if (need > NThreads) { + if (grow_array((void **)&Threads, &NThreads, sizeof(uint64_t), + need - NThreads)) { (void)fprintf(stderr, "%s: can't allocate space for %d Threads\n", - Pn, (int)(NbThreads / sizeof(int *))); + Pn, need); Error(ctx); } } /* * Get thread information for the process. */ - nb = proc_pidinfo(pid, PROC_PIDLISTTHREADS, 0, Threads, NbThreads); + nb = proc_pidinfo(pid, PROC_PIDLISTTHREADS, 0, Threads, + (int)(NThreads * sizeof(uint64_t))); if (nb <= 0) { if (errno == ESRCH) {