diff --git a/CHANGES b/CHANGES index 5e15b8e..6df1b49 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ document that the iob_write callback should limit itself fix mmap_shared add iob_free, add man pages for iob_free and iob_reset + fix descriptor leak in iob_addfile_close if the range was 0 (oops) 0.21: errno cleanup and man page updates (Rolf Eike Beer) diff --git a/io/iob_addbuf_internal.c b/io/iob_addbuf_internal.c index bba8fe1..760ff0d 100644 --- a/io/iob_addbuf_internal.c +++ b/io/iob_addbuf_internal.c @@ -1,8 +1,12 @@ #include "iob_internal.h" int iob_addbuf_internal(io_batch* b,const void* buf,uint64 n,int _free) { - iob_entry* e=array_allocate(&b->b,sizeof(iob_entry), - array_length(&b->b,sizeof(iob_entry))); + iob_entry* e; + if (!n) { + if (_free) free(buf); + return 1; + } + e=array_allocate(&b->b,sizeof(iob_entry),array_length(&b->b,sizeof(iob_entry))); if (!e) return 0; e->type=_free?FROMBUF_FREE:FROMBUF; e->fd=-1; diff --git a/io/iob_addfile_close.c b/io/iob_addfile_close.c index 3aa65d9..764fa64 100644 --- a/io/iob_addfile_close.c +++ b/io/iob_addfile_close.c @@ -2,7 +2,10 @@ int iob_addfile_close(io_batch* b,int64 fd,uint64 off,uint64 n) { iob_entry* e; - if (n==0) return 1; + if (n==0) { + io_close(fd); + return 1; + } io_fd(fd); e=array_allocate(&b->b,sizeof(iob_entry), array_length(&b->b,sizeof(iob_entry)));