Commit 0a6bfbc9 authored by Mark Andrews's avatar Mark Andrews
Browse files

handle realloc failure [RT #32105]

parent 8dda0f67
......@@ -514,12 +514,12 @@ t_fgetbs(FILE *fp) {
int c;
size_t n;
size_t size;
char *buf;
char *buf, *old;
char *p;
n = 0;
size = T_BUFSIZ;
buf = (char *) malloc(T_BUFSIZ * sizeof(char));
n = 0;
size = T_BUFSIZ;
old = buf = (char *) malloc(T_BUFSIZ * sizeof(char));
if (buf != NULL) {
p = buf;
......@@ -535,7 +535,8 @@ t_fgetbs(FILE *fp) {
buf = (char *)realloc(buf,
size * sizeof(char));
if (buf == NULL)
break;
goto err;
old = buf;
p = buf + n;
}
}
......@@ -546,7 +547,10 @@ t_fgetbs(FILE *fp) {
}
return (buf);
} else {
fprintf(stderr, "malloc failed %d", errno);
err:
if (old != NULL)
free(old);
fprintf(stderr, "malloc/realloc failed %d", errno);
return(NULL);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment