From 7d23150ae429fccb5878e72a019938e7f8ba35d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Fri, 2 Mar 2012 11:39:38 +0100 Subject: [PATCH] fix: make sure file descriptors are closed when serving recordings via http --- src/webui/webui.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/webui/webui.c b/src/webui/webui.c index 2d812615..57362abe 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -569,14 +569,19 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque) sscanf(range, "bytes=%"PRId64"-%"PRId64"", &file_start, &file_end); //Sanity checks - if(file_start < 0 || file_start >= st.st_size) + if(file_start < 0 || file_start >= st.st_size) { + close(fd); return 200; + } + if(file_end < 0 || file_end >= st.st_size) { + close(fd); + return 200; + } - if(file_end < 0 || file_end >= st.st_size) - return 200; - - if(file_start > file_end) + if(file_start > file_end) { + close(fd); return 200; + } content_len = file_end - file_start+1; @@ -609,8 +614,10 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque) while(content_len > 0) { chunk = MIN(1024 * 1024 * 1024, content_len); r = sendfile(hc->hc_fd, fd, NULL, chunk); - if(r == -1) + if(r == -1) { + close(fd); return -1; + } content_len -= r; } }