88489be542
Ok, here is that rather major internal redesign hinted at in the three previous commits. Its need was quickly revealed after adapting top then attempting to display newly added 'CGNAME' fields and an existing 'CGROUPS'. That very quickly generated a SEGV. And the reason was just as quickly recognized. Both fields relied on that proc_t.cgroup member yet whichever result structure is first in a stack is the one which assumes ownership of of the vectored sting by resetting its cgroup to NULL. So this commit introduces reference counting for a few of the fields in the proc_t. Specifically there are 17 entries in the Item_table dealing with strings/vectors where ownership is transferred to newlib. Now whenever such fields are represented more than once in a stack, the strings will be duplicated instead of transferred. In this way we can generally remain optimized avoiding string copies, yet still accommodate them when needed. There's an exception to this scheme: those true string vectors (CGROUP_V, CMDLINE_V and ENVIRON_V). When such fields are duplicated in a stack the result structures beyond the first will be set to NULL, which the caller will (should) already be equipped to deal with anyway. Signed-off-by: Jim Warner <james.warner@comcast.net>