library: refactor exposed pointers management, 3rd gen
This commit brings all of those 'fetch' type functions (supporting some form of 'reap') into closer alignment with one another. The biggest impact is to be found in the <stat> module, which now provides for the separate copy of stack pointers which will be exposed to users. The reason such a copy was not employed initially with <stat>, unlike those for <pids> and <slabinfo>, is due to the fact that such stacks were never sortable. Thus the original raw consolidated extent pointers wouldn't have been disturbed. But that meant no NULL delimiter. So with this commit, all reap/fetch operations now use pointer copies when returning results to callers. And, all such arrays are now NULL delimited meaning callers can choose their own access fencepost: totals or NULL. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
10
proc/pids.c
10
proc/pids.c
@ -1090,14 +1090,16 @@ static int stacks_fetch (
|
||||
// finalize stuff -------------------------------------
|
||||
/* note: we go to this trouble of maintaining a duplicate of the consolidated |
|
||||
extent stacks addresses represented as our 'anchor' since these ptrs |
|
||||
are exposed to users ( um, not that we don't trust 'em or anything ) | */
|
||||
if (n_saved < n_alloc + 1) {
|
||||
n_saved = n_alloc + 1;
|
||||
are exposed to a user (um, not that we don't trust 'em or anything). |
|
||||
plus, we can NULL delimit these ptrs which we couldn't do otherwise. | */
|
||||
if (n_saved < n_inuse + 1) {
|
||||
n_saved = n_inuse + 1;
|
||||
if (!(info->fetch.results.stacks = realloc(info->fetch.results.stacks, sizeof(void *) * n_saved)))
|
||||
return -1;
|
||||
return -ENOMEM;
|
||||
}
|
||||
memcpy(info->fetch.results.stacks, info->fetch.anchor, sizeof(void *) * n_inuse);
|
||||
info->fetch.results.stacks[n_inuse] = NULL;
|
||||
|
||||
return n_inuse; // callers beware, this might be zero !
|
||||
#undef n_alloc
|
||||
#undef n_inuse
|
||||
|
Reference in New Issue
Block a user