diff options
author | Mark Andrews <marka@isc.org> | 2013-06-11 16:08:16 +1000 |
---|---|---|
committer | Mark Andrews <marka@isc.org> | 2013-06-11 16:08:16 +1000 |
commit | 6d210be23379eed71f096f80d7859cbbeb347596 (patch) | |
tree | 531f4b021fc3748cd9bc69d25d63760c7f63cb42 /tests | |
parent | 74d67492a1582b9722444c2693f2c4b9e969e1b7 (diff) | |
download | isc-dhcp-6d210be23379eed71f096f80d7859cbbeb347596.tar.gz |
handle realloc failure [RT #32105]
Diffstat (limited to 'tests')
-rw-r--r-- | tests/t_api.c | 16 |
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); } } |