Fix calls to {m,c,re}alloc so that they use x{m,c,re}alloc instead of

segfaulting or handling errors the same way themselves.
This commit is contained in:
Matt Kraai 2000-09-13 02:46:14 +00:00
parent b89075298e
commit 322ae93a5e
25 changed files with 70 additions and 108 deletions

14
ar.c
View File

@ -246,7 +246,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
headerL_t *list;
off_t initialOffset;
list = (headerL_t *) malloc(sizeof(headerL_t));
list = (headerL_t *) xmalloc(sizeof(headerL_t));
initialOffset=lseek(srcFd, 0, SEEK_CUR);
if (checkArMagic(srcFd)==TRUE)
ar=TRUE;
@ -258,7 +258,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
if (tar==TRUE) {
while(readTarHeader(srcFd, list)==TRUE) {
off_t tarOffset;
list->next = (headerL_t *) malloc(sizeof(headerL_t));
list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*list->next = *head;
*head = *list;
@ -282,7 +282,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
if (readArEntry(srcFd, list) == FALSE)
return(head);
}
list->next = (headerL_t *) malloc(sizeof(headerL_t));
list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*list->next = *head;
*head = *list;
/* recursive check for sub-archives */
@ -349,9 +349,9 @@ extern int ar_main(int argc, char **argv)
return (FALSE);
}
optind++;
entry = (headerL_t *) malloc(sizeof(headerL_t));
header = (headerL_t *) malloc(sizeof(headerL_t));
extractList = (headerL_t *) malloc(sizeof(headerL_t));
entry = (headerL_t *) xmalloc(sizeof(headerL_t));
header = (headerL_t *) xmalloc(sizeof(headerL_t));
extractList = (headerL_t *) xmalloc(sizeof(headerL_t));
header = getHeaders(srcFd, header, funct);
/* find files to extract or display */
@ -359,7 +359,7 @@ extern int ar_main(int argc, char **argv)
/* only handle specified files */
while(optind < argc) {
if ( (entry = findEntry(header, argv[optind])) != NULL) {
entry->next = (headerL_t *) malloc(sizeof(headerL_t));
entry->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*entry->next = *extractList;
*extractList = *entry;
}

View File

@ -246,7 +246,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
headerL_t *list;
off_t initialOffset;
list = (headerL_t *) malloc(sizeof(headerL_t));
list = (headerL_t *) xmalloc(sizeof(headerL_t));
initialOffset=lseek(srcFd, 0, SEEK_CUR);
if (checkArMagic(srcFd)==TRUE)
ar=TRUE;
@ -258,7 +258,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
if (tar==TRUE) {
while(readTarHeader(srcFd, list)==TRUE) {
off_t tarOffset;
list->next = (headerL_t *) malloc(sizeof(headerL_t));
list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*list->next = *head;
*head = *list;
@ -282,7 +282,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
if (readArEntry(srcFd, list) == FALSE)
return(head);
}
list->next = (headerL_t *) malloc(sizeof(headerL_t));
list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*list->next = *head;
*head = *list;
/* recursive check for sub-archives */
@ -349,9 +349,9 @@ extern int ar_main(int argc, char **argv)
return (FALSE);
}
optind++;
entry = (headerL_t *) malloc(sizeof(headerL_t));
header = (headerL_t *) malloc(sizeof(headerL_t));
extractList = (headerL_t *) malloc(sizeof(headerL_t));
entry = (headerL_t *) xmalloc(sizeof(headerL_t));
header = (headerL_t *) xmalloc(sizeof(headerL_t));
extractList = (headerL_t *) xmalloc(sizeof(headerL_t));
header = getHeaders(srcFd, header, funct);
/* find files to extract or display */
@ -359,7 +359,7 @@ extern int ar_main(int argc, char **argv)
/* only handle specified files */
while(optind < argc) {
if ( (entry = findEntry(header, argv[optind])) != NULL) {
entry->next = (headerL_t *) malloc(sizeof(headerL_t));
entry->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*entry->next = *extractList;
*extractList = *entry;
}

View File

@ -246,11 +246,11 @@ char** username_tab_completion(char* command, int *num_matches)
char** exe_n_cwd_tab_completion(char* command, int *num_matches)
{
char *dirName;
char **matches = (char **) NULL;
char **matches;
DIR *dir;
struct dirent *next;
matches = malloc( sizeof(char*)*50);
matches = xmalloc( sizeof(char*)*50);
/* Stick a wildcard onto the command, for later use */
strcat( command, "*");
@ -273,7 +273,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches)
/* See if this matches */
if (check_wildcard_match(next->d_name, command) == TRUE) {
/* Cool, found a match. Add it to the list */
matches[*num_matches] = malloc(strlen(next->d_name)+1);
matches[*num_matches] = xmalloc(strlen(next->d_name)+1);
strcpy( matches[*num_matches], next->d_name);
++*num_matches;
//matches = realloc( matches, sizeof(char*)*(*num_matches));
@ -302,7 +302,7 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
/* Make a local copy of the string -- up
* to the position of the cursor */
matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
strncpy(matchBuf, command, cursor);
tmp=matchBuf;
@ -670,8 +670,8 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
if (!h) {
/* No previous history -- this memory is never freed */
h = his_front = malloc(sizeof(struct history));
h->n = malloc(sizeof(struct history));
h = his_front = xmalloc(sizeof(struct history));
h->n = xmalloc(sizeof(struct history));
h->p = NULL;
h->s = strdup(command);
@ -682,7 +682,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
history_counter++;
} else {
/* Add a new history command -- this memory is never freed */
h->n = malloc(sizeof(struct history));
h->n = xmalloc(sizeof(struct history));
h->n->p = h;
h->n->n = NULL;

View File

@ -102,12 +102,8 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
u_short unicode;
maxct = tailsz; /* more than enough */
up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
if (!up) {
errorMsg("Out of memory?\n");
exit(1);
}
for (glyph = 0; glyph < fontsize; glyph++) {
while (tailsz >= 2) {
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];

View File

@ -67,11 +67,7 @@ int loadkmap_main(int argc, char **argv)
exit(FALSE);
}
ibuff = (u_short *) malloc(ibuffsz);
if (!ibuff) {
errorMsg("Out of memory.\n");
exit(FALSE);
}
ibuff = (u_short *) xmalloc(ibuffsz);
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
if (flags[i] == 1) {

View File

@ -90,7 +90,7 @@ extern int ln_main(int argc, char **argv)
if (linkIntoDirFlag == TRUE) {
char *baseName = get_last_path_component(*argv);
linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
strcpy(linkName, dirName);
if(dirName[strlen(dirName)-1] != '/')
strcat(linkName, "/");

View File

@ -64,7 +64,7 @@ static const int max = 1024;
static Line *line_alloc()
{
Line *self;
self = malloc(1 * sizeof(Line));
self = xmalloc(1 * sizeof(Line));
return self;
}
@ -76,9 +76,6 @@ static Line *line_newFromFile(FILE * src)
if ((cstring = get_line_from_file(src))) {
self = line_alloc();
if (self == NULL) {
return NULL;
}
self->data = cstring;
self->next = NULL;
return self;
@ -173,10 +170,7 @@ static List *list_sort(List * self, Compare * compare)
Line *line;
/* mallocate array of Line*s */
self->sorted = (Line **) malloc(self->len * sizeof(Line *));
if (self->sorted == NULL) {
return NULL;
}
self->sorted = (Line **) xmalloc(self->len * sizeof(Line *));
/* fill array w/ List's contents */
i = 0;
@ -294,4 +288,4 @@ int sort_main(int argc, char **argv)
return(0);
}
/* $Id: sort.c,v 1.20 2000/07/16 20:57:15 kraai Exp $ */
/* $Id: sort.c,v 1.21 2000/09/13 02:46:13 kraai Exp $ */

View File

@ -87,12 +87,12 @@ int tail_stream(int fd)
ssize_t f_size=0;
bs=BUFSIZ;
line=malloc(bs);
line=xmalloc(bs);
while(1) {
bytes_read=read(fd,line,bs);
if(bytes_read<=0)
break;
buffer=realloc(buffer,f_size+bytes_read);
buffer=xrealloc(buffer,f_size+bytes_read);
memcpy(&buffer[f_size],line,bytes_read);
filelocation=f_size+=bytes_read;
}
@ -150,8 +150,8 @@ int tail_stream(int fd)
void add_file(char *name)
{
++n_files;
files = realloc(files, n_files);
files[n_files - 1] = (char *) malloc(strlen(name) + 1);
files = xrealloc(files, n_files);
files[n_files - 1] = (char *) xmalloc(strlen(name) + 1);
strcpy(files[n_files - 1], name);
}
@ -268,13 +268,13 @@ int tail_main(int argc, char **argv)
units=-11;
if(units>0)
units--;
fd=malloc(sizeof(int)*n_files);
fd=xmalloc(sizeof(int)*n_files);
if (n_files == 1)
#ifndef BB_FEATURE_SIMPLE_TAIL
if (!verbose)
#endif
show_headers = 0;
buffer=malloc(BUFSIZ);
buffer=xmalloc(BUFSIZ);
for (test = 0; test < n_files; test++) {
if (show_headers)
printf("==> %s <==\n", files[test]);

View File

@ -555,9 +555,7 @@ static void
initialize_group_array ()
{
ngroups = getgroups(0, NULL);
if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
fatalError("Out of space\n");
group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
getgroups(ngroups, group_array);
}

View File

@ -44,7 +44,6 @@
*/
#include <stdio.h>
#include <stdlib.h> /* for realloc() */
#include <unistd.h> /* for getopt() */
#include <regex.h>
#include <string.h> /* for strdup() */
@ -457,7 +456,7 @@ static void add_cmd_str(const char *cmdstr)
continue;
}
/* grow the array */
sed_cmds = realloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
sed_cmds = xrealloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
/* zero new element */
memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd));
/* load command string into new array element, get remainder */
@ -481,7 +480,7 @@ static void load_cmd_file(char *filename)
/* if a line ends with '\' it needs the next line appended to it */
while (line[strlen(line)-2] == '\\' &&
(nextline = get_line_from_file(cmdfile)) != NULL) {
line = realloc(line, strlen(line) + strlen(nextline) + 1);
line = xrealloc(line, strlen(line) + strlen(nextline) + 1);
strcat(line, nextline);
free(nextline);
}

View File

@ -40,7 +40,7 @@ extern int which_main(int argc, char **argv)
if (!path_list)
path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin";
path_parsed = malloc (strlen(path_list) + 1);
path_parsed = xmalloc (strlen(path_list) + 1);
strcpy (path_parsed, path_list);
/* Replace colons with zeros in path_parsed and count them */

2
ln.c
View File

@ -90,7 +90,7 @@ extern int ln_main(int argc, char **argv)
if (linkIntoDirFlag == TRUE) {
char *baseName = get_last_path_component(*argv);
linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
strcpy(linkName, dirName);
if(dirName[strlen(dirName)-1] != '/')
strcat(linkName, "/");

View File

@ -102,12 +102,8 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
u_short unicode;
maxct = tailsz; /* more than enough */
up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
if (!up) {
errorMsg("Out of memory?\n");
exit(1);
}
for (glyph = 0; glyph < fontsize; glyph++) {
while (tailsz >= 2) {
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];

View File

@ -67,11 +67,7 @@ int loadkmap_main(int argc, char **argv)
exit(FALSE);
}
ibuff = (u_short *) malloc(ibuffsz);
if (!ibuff) {
errorMsg("Out of memory.\n");
exit(FALSE);
}
ibuff = (u_short *) xmalloc(ibuffsz);
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
if (flags[i] == 1) {

View File

@ -273,7 +273,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
if (numfilesystems<0)
fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno));
fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype));
fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype));
/* Grab the list of available filesystems */
status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
@ -343,7 +343,7 @@ extern int mount_main(int argc, char **argv)
numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
if (numfilesystems<0)
fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno));
mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent));
mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
/* Grab the list of mounted filesystems */
if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)

View File

@ -229,7 +229,7 @@ extern int ps_main(int argc, char **argv)
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */

2
ps.c
View File

@ -229,7 +229,7 @@ extern int ps_main(int argc, char **argv)
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */

5
sed.c
View File

@ -44,7 +44,6 @@
*/
#include <stdio.h>
#include <stdlib.h> /* for realloc() */
#include <unistd.h> /* for getopt() */
#include <regex.h>
#include <string.h> /* for strdup() */
@ -457,7 +456,7 @@ static void add_cmd_str(const char *cmdstr)
continue;
}
/* grow the array */
sed_cmds = realloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
sed_cmds = xrealloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
/* zero new element */
memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd));
/* load command string into new array element, get remainder */
@ -481,7 +480,7 @@ static void load_cmd_file(char *filename)
/* if a line ends with '\' it needs the next line appended to it */
while (line[strlen(line)-2] == '\\' &&
(nextline = get_line_from_file(cmdfile)) != NULL) {
line = realloc(line, strlen(line) + strlen(nextline) + 1);
line = xrealloc(line, strlen(line) + strlen(nextline) + 1);
strcat(line, nextline);
free(nextline);
}

View File

@ -246,11 +246,11 @@ char** username_tab_completion(char* command, int *num_matches)
char** exe_n_cwd_tab_completion(char* command, int *num_matches)
{
char *dirName;
char **matches = (char **) NULL;
char **matches;
DIR *dir;
struct dirent *next;
matches = malloc( sizeof(char*)*50);
matches = xmalloc( sizeof(char*)*50);
/* Stick a wildcard onto the command, for later use */
strcat( command, "*");
@ -273,7 +273,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches)
/* See if this matches */
if (check_wildcard_match(next->d_name, command) == TRUE) {
/* Cool, found a match. Add it to the list */
matches[*num_matches] = malloc(strlen(next->d_name)+1);
matches[*num_matches] = xmalloc(strlen(next->d_name)+1);
strcpy( matches[*num_matches], next->d_name);
++*num_matches;
//matches = realloc( matches, sizeof(char*)*(*num_matches));
@ -302,7 +302,7 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
/* Make a local copy of the string -- up
* to the position of the cursor */
matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
strncpy(matchBuf, command, cursor);
tmp=matchBuf;
@ -670,8 +670,8 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
if (!h) {
/* No previous history -- this memory is never freed */
h = his_front = malloc(sizeof(struct history));
h->n = malloc(sizeof(struct history));
h = his_front = xmalloc(sizeof(struct history));
h->n = xmalloc(sizeof(struct history));
h->p = NULL;
h->s = strdup(command);
@ -682,7 +682,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
history_counter++;
} else {
/* Add a new history command -- this memory is never freed */
h->n = malloc(sizeof(struct history));
h->n = xmalloc(sizeof(struct history));
h->n->p = h;
h->n->n = NULL;

12
sort.c
View File

@ -64,7 +64,7 @@ static const int max = 1024;
static Line *line_alloc()
{
Line *self;
self = malloc(1 * sizeof(Line));
self = xmalloc(1 * sizeof(Line));
return self;
}
@ -76,9 +76,6 @@ static Line *line_newFromFile(FILE * src)
if ((cstring = get_line_from_file(src))) {
self = line_alloc();
if (self == NULL) {
return NULL;
}
self->data = cstring;
self->next = NULL;
return self;
@ -173,10 +170,7 @@ static List *list_sort(List * self, Compare * compare)
Line *line;
/* mallocate array of Line*s */
self->sorted = (Line **) malloc(self->len * sizeof(Line *));
if (self->sorted == NULL) {
return NULL;
}
self->sorted = (Line **) xmalloc(self->len * sizeof(Line *));
/* fill array w/ List's contents */
i = 0;
@ -294,4 +288,4 @@ int sort_main(int argc, char **argv)
return(0);
}
/* $Id: sort.c,v 1.20 2000/07/16 20:57:15 kraai Exp $ */
/* $Id: sort.c,v 1.21 2000/09/13 02:46:13 kraai Exp $ */

12
tail.c
View File

@ -87,12 +87,12 @@ int tail_stream(int fd)
ssize_t f_size=0;
bs=BUFSIZ;
line=malloc(bs);
line=xmalloc(bs);
while(1) {
bytes_read=read(fd,line,bs);
if(bytes_read<=0)
break;
buffer=realloc(buffer,f_size+bytes_read);
buffer=xrealloc(buffer,f_size+bytes_read);
memcpy(&buffer[f_size],line,bytes_read);
filelocation=f_size+=bytes_read;
}
@ -150,8 +150,8 @@ int tail_stream(int fd)
void add_file(char *name)
{
++n_files;
files = realloc(files, n_files);
files[n_files - 1] = (char *) malloc(strlen(name) + 1);
files = xrealloc(files, n_files);
files[n_files - 1] = (char *) xmalloc(strlen(name) + 1);
strcpy(files[n_files - 1], name);
}
@ -268,13 +268,13 @@ int tail_main(int argc, char **argv)
units=-11;
if(units>0)
units--;
fd=malloc(sizeof(int)*n_files);
fd=xmalloc(sizeof(int)*n_files);
if (n_files == 1)
#ifndef BB_FEATURE_SIMPLE_TAIL
if (!verbose)
#endif
show_headers = 0;
buffer=malloc(BUFSIZ);
buffer=xmalloc(BUFSIZ);
for (test = 0; test < n_files; test++) {
if (show_headers)
printf("==> %s <==\n", files[test]);

4
test.c
View File

@ -555,9 +555,7 @@ static void
initialize_group_array ()
{
ngroups = getgroups(0, NULL);
if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
fatalError("Out of space\n");
group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
getgroups(ngroups, group_array);
}

View File

@ -273,7 +273,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
if (numfilesystems<0)
fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno));
fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype));
fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype));
/* Grab the list of available filesystems */
status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
@ -343,7 +343,7 @@ extern int mount_main(int argc, char **argv)
numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
if (numfilesystems<0)
fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno));
mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent));
mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
/* Grab the list of mounted filesystems */
if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)

View File

@ -1290,7 +1290,7 @@ extern pid_t* findPidByName( char* pidName)
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */
@ -1316,9 +1316,7 @@ extern pid_t* findPidByName( char* pidName)
if ((strstr(info.command_line, pidName) != NULL)
&& (strlen(pidName) == strlen(info.command_line))) {
pidList=realloc( pidList, sizeof(pid_t) * (j+2));
if (pidList==NULL)
fatalError(memory_exhausted);
pidList=xrealloc( pidList, sizeof(pid_t) * (j+2));
pidList[j++]=info.pid;
}
}
@ -1389,9 +1387,7 @@ extern pid_t* findPidByName( char* pidName)
if ((strstr(p, pidName) != NULL)
&& (strlen(pidName) == strlen(p))) {
pidList=realloc( pidList, sizeof(pid_t) * (i+2));
if (pidList==NULL)
fatalError(memory_exhausted);
pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
pidList[i++]=strtol(next->d_name, NULL, 0);
}
}
@ -1624,7 +1620,7 @@ extern char *get_line_from_file(FILE *file)
break;
/* grow the line buffer as necessary */
if (idx > linebufsz-2)
linebuf = realloc(linebuf, linebufsz += GROWBY);
linebuf = xrealloc(linebuf, linebufsz += GROWBY);
linebuf[idx++] = (char)ch;
if ((char)ch == '\n')
break;

View File

@ -40,7 +40,7 @@ extern int which_main(int argc, char **argv)
if (!path_list)
path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin";
path_parsed = malloc (strlen(path_list) + 1);
path_parsed = xmalloc (strlen(path_list) + 1);
strcpy (path_parsed, path_list);
/* Replace colons with zeros in path_parsed and count them */