#include <sys/mman.h>
#include <sys/utsname.h>
#include "procps.h"
+#include "alloc.h"
#include "version.h"
#include "sysinfo.h" /* smp_num_cpus */
#include "wchan.h" // to verify prototypes
unsigned room = *roomp;
if(!room) goto hell; /* failed before */
- if(!buf) buf = malloc(room);
- if(!buf) goto hell;
+ if(!buf) buf = xmalloc(room);
open_again:
fd = open(filename, O_RDONLY|O_NOCTTY|O_NONBLOCK);
if(fd<0){
total += done;
/* more to go, but no room in buffer */
room *= 2;
- tmp = realloc(buf, room);
- if(!tmp) goto hell;
+ tmp = xrealloc(buf, room);
buf = tmp;
continue;
}
for(;;){
void *vp;
idx_room *= 2;
- vp = realloc(ksyms_index, sizeof(symb)*idx_room);
- if(!vp) goto bad_alloc;
+ vp = xrealloc(ksyms_index, sizeof(symb)*idx_room);
ksyms_index = vp;
bypass:
for(;;){
}
}
- if(0){
-bad_alloc:
- fprintf(stderr, "Warning: not enough memory available\n");
- }
if(0){
bad_parse:
fprintf(stderr, "Warning: "KSYMS_FILENAME" not normal\n");
for(;;){
void *vp;
sysmap_room *= 2;
- vp = realloc(sysmap_index, sizeof(symb)*sysmap_room);
- if(!vp) goto bad_alloc;
+ vp = xrealloc(sysmap_index, sizeof(symb)*sysmap_room);
sysmap_index = vp;
for(;;){
char *vstart;
message("Warning: %s has an incorrect kernel version.\n", filename);
}
if(0){
-bad_alloc:
- message("Warning: not enough memory available\n");
- }
- if(0){
bad_parse:
message("Warning: %s not parseable as a System.map\n", filename);
}
if (' ' == P->supgid[j])
P->supgid[j] = ',';
} else
- P->supgid = strdup("-");
+ P->supgid = xstrdup("-");
continue;
}
case_CapBnd:
int t;
if (!p->supgid || '-' == *p->supgid) {
- p->supgrp = strdup("-");
+ p->supgrp = xstrdup("-");
return;
}
s = p->supgid;
do {
if (',' == *s) ++s;
g = group_from_gid((uid_t)strtol(s, &s, 10));
- p->supgrp = realloc(p->supgrp, P_G_SZ+t+2);
+ p->supgrp = xrealloc(p->supgrp, P_G_SZ+t+2);
t += snprintf(p->supgrp+t, P_G_SZ+2, "%s%s", t ? "," : "", g);
} while (*s);
}
tot = strlen(src) + 1; // prep for our vectors
adj = (pSZ-1) - ((tot + pSZ-1) & (pSZ-1)); // calc alignment bytes
- cpy = xcalloc(NULL, tot + adj + (2 * pSZ)); // get new larger buffer
+ cpy = xcalloc(tot + adj + (2 * pSZ)); // get new larger buffer
snprintf(cpy, tot, "%s", src); // duplicate their string
vec = (char**)(cpy + tot + adj); // prep pointer to pointers
*vec = cpy; // point 1st vector to string
// }
saved_p = p;
- if(!p) p = xcalloc(NULL, sizeof *p);
+ if(!p) p = xcalloc(sizeof *p);
else free_acquired(p, 1);
for(;;){
proc_t *saved_t;
saved_t = t;
- if(!t) t = xcalloc(NULL, sizeof *t);
+ if(!t) t = xcalloc(sizeof *t);
else free_acquired(t, 1);
// 1. got to fake a thread for old kernels
proc_t *saved_x, *ret;
saved_x = x;
- if (!x) x = xcalloc(NULL, sizeof(*x));
+ if (!x) x = xcalloc(sizeof(*x));
else free_acquired(x,1);
if (new_p) goto next_task;
if(n_alloc == n_used){
//proc_t *old = data;
n_alloc = n_alloc*5/4+30; // grow by over 25%
- data = realloc(data,sizeof(proc_t)*n_alloc);
- //if(!data) return NULL;
+ data = xrealloc(data,sizeof(proc_t)*n_alloc);
memset(data+n_used, 0, sizeof(proc_t)*(n_alloc-n_used));
}
if(n_proc_alloc == n_proc){
//proc_t **old = ptab;
n_proc_alloc = n_proc_alloc*5/4+30; // grow by over 25%
- ptab = realloc(ptab,sizeof(proc_t*)*n_proc_alloc);
- //if(!ptab) return NULL;
+ ptab = xrealloc(ptab,sizeof(proc_t*)*n_proc_alloc);
}
tmp = readproc_direct(PT, data+n_used);
if(!tmp) break;
if(n_alloc == n_used){
proc_t *old = data;
n_alloc = n_alloc*5/4+30; // grow by over 25%
- data = realloc(data,sizeof(proc_t)*n_alloc);
+ data = xrealloc(data,sizeof(proc_t)*n_alloc);
// have to move tmp too
tmp = data+(tmp-old);
- //if(!data) return NULL;
memset(data+n_used+1, 0, sizeof(proc_t)*(n_alloc-(n_used+1)));
}
if(n_task_alloc == n_task){
//proc_t **old = ttab;
n_task_alloc = n_task_alloc*5/4+1; // grow by over 25%
- ttab = realloc(ttab,sizeof(proc_t*)*n_task_alloc);
- //if(!ttab) return NULL;
+ ttab = xrealloc(ttab,sizeof(proc_t*)*n_task_alloc);
}
t = readtask_direct(PT, tmp, data+n_used);
if(!t) break;
for (;;) {
if (n_alloc == n_used) {
n_alloc = n_alloc*5/4+30; // grow by over 25%
- tab = realloc(tab,sizeof(proc_t*)*n_alloc);
+ tab = xrealloc(tab,sizeof(proc_t*)*n_alloc);
}
// let this next guy allocate the necessary proc_t storage
// (or recycle it) since he can't tolerate realloc relocations
#include <unistd.h>
#include <fcntl.h>
+#include "alloc.h"
#include "version.h"
#include "sysinfo.h" /* include self to verify prototypes */
}
fields = sscanf(buff, " %*d %*d %15s %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %u", devname, &dummy);
if (fields == 2 && is_disk(devname)){
- (*disks) = realloc(*disks, (cDisk+1)*sizeof(struct disk_stat));
+ (*disks) = xrealloc(*disks, (cDisk+1)*sizeof(struct disk_stat));
sscanf(buff, " %*d %*d %15s %u %u %llu %u %u %u %llu %u %u %u %u",
//&disk_major,
//&disk_minor,
(*disks)[cDisk].partitions=0;
cDisk++;
}else{
- (*partitions) = realloc(*partitions, (cPartition+1)*sizeof(struct partition_stat));
+ (*partitions) = xrealloc(*partitions, (cPartition+1)*sizeof(struct partition_stat));
fflush(stdout);
sscanf(buff, (fields == 2)
? " %*d %*d %15s %u %*u %llu %*u %u %*u %llu %*u %*u %*u %*u"
while (fgets(buff,BUFFSIZE-1,fd)){
if(!memcmp("slabinfo - version:",buff,19)) continue; // skip header
if(*buff == '#') continue; // skip comments
- (*slab) = realloc(*slab, (cSlab+1)*sizeof(struct slab_cache));
+ (*slab) = xrealloc(*slab, (cSlab+1)*sizeof(struct slab_cache));
sscanf(buff, "%47s %u %u %u %u", // allow 47; max seen is 24
(*slab)[cSlab].name,
&(*slab)[cSlab].active_objs,