diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2023-02-01 21:11:11 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2023-05-03 23:11:34 -0400 |
commit | 699e0e46314762ea0e17ea4c175804a4f7af8d65 (patch) | |
tree | dac6eeaee883c31120e797a9ed3f17c17bdcd80f /src/mod_dirlisting.c | |
parent | 88607b497ba67033321db459430d6f9d1cf33ee0 (diff) | |
download | lighttpd-git-699e0e46314762ea0e17ea4c175804a4f7af8d65.tar.gz |
[mod_dirlisting] _WIN32 close files before unlink
Diffstat (limited to 'src/mod_dirlisting.c')
-rw-r--r-- | src/mod_dirlisting.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c index f65a82ee..5564197e 100644 --- a/src/mod_dirlisting.c +++ b/src/mod_dirlisting.c @@ -173,12 +173,12 @@ static void mod_dirlisting_handler_ctx_free (handler_ctx *hctx) { } if (hctx->jb) { chunk_buffer_release(hctx->jb); + if (-1 != hctx->jfd) + close(hctx->jfd); if (hctx->jfn) { unlink(hctx->jfn); free(hctx->jfn); } - if (-1 != hctx->jfd) - close(hctx->jfd); } free(hctx->path); free(hctx); @@ -1385,11 +1385,11 @@ static void mod_dirlisting_json_append (request_st * const r, handler_ctx * cons if (hctx->jfn) { if (__builtin_expect( (write_all(hctx->jfd, BUF_PTR_LEN(jb)) < 0), 0)) { /*(cleanup, cease caching if error occurs writing to cache file)*/ + close(hctx->jfd); + hctx->jfd = -1; unlink(hctx->jfn); free(hctx->jfn); hctx->jfn = NULL; - close(hctx->jfd); - hctx->jfd = -1; } /* Note: writing cache file is separate from the response so that if an * error occurs with cache, the response still proceeds. While this is @@ -1700,8 +1700,9 @@ static void mod_dirlisting_cache_add (request_st * const r, handler_ctx * const memcpy(oldpath, tb->ptr, len+7+1); /*(include '\0')*/ const int fd = fdevent_mkostemp(oldpath, 0); if (fd < 0) return; - if (mod_dirlisting_write_cq(fd, &r->write_queue, r->conf.errh) - && 0 == fdevent_rename(oldpath, newpath)) { + int rc = mod_dirlisting_write_cq(fd, &r->write_queue, r->conf.errh); + close(fd); + if (rc && 0 == fdevent_rename(oldpath, newpath)) { stat_cache_invalidate_entry(newpath, len); /* Cache-Control and ETag (also done in mod_dirlisting_cache_check())*/ mod_dirlisting_cache_control(r, hctx->conf.cache->max_age); @@ -1717,7 +1718,6 @@ static void mod_dirlisting_cache_add (request_st * const r, handler_ctx * const } else unlink(oldpath); - close(fd); } @@ -1753,6 +1753,8 @@ static void mod_dirlisting_cache_json (request_st * const r, handler_ctx * const force_assert(len < PATH_MAX); memcpy(newpath, hctx->jfn, len); newpath[len] = '\0'; + close(hctx->jfd); + hctx->jfd = -1; if (0 == fdevent_rename(hctx->jfn, newpath)) stat_cache_invalidate_entry(newpath, len); else |