Subject: | 0.41 segfaults on MacOS 10.4.x (i386 and ppc) |
'make test' failed for me on ppc/10.4.7, but passed on ppc/10.3.8 and
i386/10.4.7. On all three platforms, when I used Proc::ProcessTable in
an app, it would seg fault (included with the example.pl script).
os/darwin.c loops over the returned kinfo_proc structures - but someone
reversed the loop and accidentally left the index counter starting at 1:
nentries = bufSize/ sizeof(struct kinfo_proc);
kinfo = malloc(nentries * sizeof(KINFO));
...
#if 1
kp += nentries - 1;
for (i = 1; i <= nentries; i++, --kp) {
#else
for (i = nentries; --i >= 0; ++kp) {
#endif
...
ki = &kinfo[i];
So the last proc will overshoot the kinfo array by 1.
The simple fix is to change the code to use 'i = 0;' -- but if you look
closer, you'll see the whole kinfo array is never used. Only 1 entry is
used at a time. The enclosed patch just removes the kinfo array and
uses a single KINFO structure.
Subject: | Proc-ProcessTable-darwin.patch |
==== //3rdparty/tmw/perl-modules/Proc-ProcessTable/os/darwin.c#1 - /mathworks/devel/sandbox/jloverso/ws/3rdparty/tmw/perl-modules/Proc-ProcessTable/os/darwin.c ====
88d87
< if (kinfo != NULL) free (kinfo); \
97d95
< KINFO *kinfo = NULL;
139,142d136
< if ((kinfo = malloc(nentries * sizeof(KINFO))) == NULL)
< DIE_HORRIBLY ("Memory allocation failure")
< memset(kinfo, 0, (nentries * sizeof(*kinfo)));
<
146a141
>
155c150,152
< KINFO *ki;
---
> KINFO kinfo;
> KINFO *ki = &kinfo;
> memset(ki, 0, sizeof(*ki));
162d158
< ki = &kinfo[i];