summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMark Andrews <marka@isc.org>2013-06-11 16:08:16 +1000
committerMark Andrews <marka@isc.org>2013-06-11 16:08:16 +1000
commit6d210be23379eed71f096f80d7859cbbeb347596 (patch)
tree531f4b021fc3748cd9bc69d25d63760c7f63cb42 /tests
parent74d67492a1582b9722444c2693f2c4b9e969e1b7 (diff)
downloadisc-dhcp-6d210be23379eed71f096f80d7859cbbeb347596.tar.gz
handle realloc failure [RT #32105]
Diffstat (limited to 'tests')
-rw-r--r--tests/t_api.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/t_api.c b/tests/t_api.c
index 23a4312a..e6162264 100644
--- a/tests/t_api.c
+++ b/tests/t_api.c
@@ -537,12 +537,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;
@@ -558,7 +558,8 @@ t_fgetbs(FILE *fp) {
buf = (char *)realloc(buf,
size * sizeof(char));
if (buf == NULL)
- break;
+ goto err;
+ old = buf;
p = buf + n;
}
}
@@ -569,7 +570,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);
}
}