commit 4d7575c0d716a2b6bbfa02a5248144f3ad399806 from: Martijn van Duren date: Wed Apr 03 09:30:59 2019 UTC Finally fix big memory leak commit - 56ffa48b3850b832a4428952374a20d654e5f4af commit + 4d7575c0d716a2b6bbfa02a5248144f3ad399806 blob - d629134e4fcaa74b7bf836a75468d74bebd0de5c blob + 0a700a0ff66e3ff542a44f3055ed3e3100ad5e08 --- smtp_proc.c +++ smtp_proc.c @@ -158,14 +158,18 @@ smtp_getline(char ** restrict buf, size_t * restrict s return strlen; } } - if (reoff - rsoff < 1500) { + /* If we can't fill at the end, move everything back. */ + if (rbsize - reoff < 1500 && rsoff != 0) { + memmove(rbuf, rbuf + rsoff, reoff - rsoff); + reoff -= rsoff; + rsoff = 0; + } + /* If we still can't fill alloc some new memory. */ + if (rbsize - reoff < 1500) { if ((rbuf = realloc(rbuf, rbsize + 4096)) == NULL) fatal(NULL); rbsize += 4096; } - // If we can't fill at the end, move everything back. - if (rbsize - reoff < 1500) - memmove(rbuf + rsoff, rbuf, reoff - rsoff); nread = read(STDIN_FILENO, rbuf + reoff, rbsize - reoff); if (nread <= 0) return nread;