diff --git a/CHANGES b/CHANGES index 4a9e9f7..1418ab2 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,7 @@ add man pages for libio, safemult fix possible signal race in io_tryread and io_trywrite (Scott Lamb) fix byte_rchr return value (Marcus Winkler) + fix bug in mmap code path of io_sendfile (David Leadbeater) 0.18: make libowfat compile on BSD again (sorry, and thanks to everyone who diff --git a/io/io_sendfile.c b/io/io_sendfile.c index b66696b..f30ef2b 100644 --- a/io/io_sendfile.c +++ b/io/io_sendfile.c @@ -139,15 +139,25 @@ int64 io_sendfile(int64 out,int64 in,uint64 off,uint64 bytes) { if (m==-1) { e->canwrite=0; e->next_write=-1; - return errno==EAGAIN?(sent?sent:-1):-3; + if (errno!=EAGAIN) { + munmap(e->mmapped,e->maplen); + e->mmapped=0; + return -3; + } + return sent?sent:-1; } if (m==0) return sent; sent+=m; left-=m; bytes-=m; off+=m; + c+=m; } } while (bytes); + if (e->mmapped) { + munmap(e->mmapped,e->maplen); + e->mmapped=0; + } return sent; } readwrite: