diff options
-rw-r--r-- | libhb/ports.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/libhb/ports.c b/libhb/ports.c index 9f5b403cc..da48d5d81 100644 --- a/libhb/ports.c +++ b/libhb/ports.c @@ -1445,14 +1445,18 @@ size_t hb_getline(char ** lineptr, size_t * n, FILE * fp) p = bufptr; while (c != EOF) { - if ((p - bufptr) > (size - 1)) + if ((p - bufptr) >= (size - 1)) { + char * tmp; size = size + 128; - bufptr = realloc(bufptr, size); - if (bufptr == NULL) + tmp = realloc(bufptr, size); + if (tmp == NULL) { + free(bufptr); return -1; } + p = tmp + (p - bufptr); + bufptr = tmp; } *p++ = c; if (c == '\n') |