ps: exploit enhanced library memory allocation provisions

There were numerous ps memory allocation inconsistencies.
Some were checked for failure and others were not.

The program was modified to utilize the library memory
rouines which are consistent in dealing with errors.

(a few changes simply removed trailing whitespace)
This commit is contained in:
Jim Warner
2011-11-22 09:36:00 -06:00
committed by Craig Small
parent 8fbe2dea04
commit 229be7b160
4 changed files with 46 additions and 52 deletions

View File

@ -29,6 +29,7 @@
#include <signal.h> /* catch signals */
#include "common.h"
#include "../proc/alloc.h"
#include "../proc/wchan.h"
#include "../proc/version.h"
#include "../proc/readproc.h"
@ -236,7 +237,7 @@ static void lists_and_needs(void){
format_node *p_end = &pfn;
format_node *t_end = &tfn;
while(walk){
format_node *new = malloc(sizeof(format_node));
format_node *new = xmalloc(sizeof(format_node));
memcpy(new,walk,sizeof(format_node));
p_end->next = walk;
t_end->next = new;
@ -380,7 +381,7 @@ static void prep_forest_sort(void){
if(!sort_list) { /* assume start time order */
incoming = search_format_array("start_time");
if(!incoming) { fprintf(stderr, "Could not find start_time!\n"); exit(1); }
tmp_list = malloc(sizeof(sort_node));
tmp_list = xmalloc(sizeof(sort_node));
tmp_list->reverse = 0;
tmp_list->typecode = '?'; /* what was this for? */
tmp_list->sr = incoming->sr;
@ -391,7 +392,7 @@ static void prep_forest_sort(void){
/* this is required for the forest option */
incoming = search_format_array("ppid");
if(!incoming) { fprintf(stderr, "Could not find ppid!\n"); exit(1); }
tmp_list = malloc(sizeof(sort_node));
tmp_list = xmalloc(sizeof(sort_node));
tmp_list->reverse = 0;
tmp_list->typecode = '?'; /* what was this for? */
tmp_list->sr = incoming->sr;