diff options
author | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2012-09-23 12:32:08 +0100 |
---|---|---|
committer | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2012-09-23 12:32:08 +0100 |
commit | afa408c7506842cea88d2a93701ce86f6c87c178 (patch) | |
tree | b7923e6f9277f792f19a93f73779adbe24131c20 | |
parent | 65486f93bf9f4b2362c53d6c6b0e170798b2e83b (diff) | |
parent | c22fbf937756a1b35085a8577e138bd1dc540eea (diff) | |
download | netsurf-afa408c7506842cea88d2a93701ce86f6c87c178.tar.gz netsurf-afa408c7506842cea88d2a93701ce86f6c87c178.tar.bz2 |
Merge branch 'master' of git://git.netsurf-browser.org/netsurf
-rw-r--r-- | content/fetchers/file.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/content/fetchers/file.c b/content/fetchers/file.c index abedaa7b3..73bfbdb3b 100644 --- a/content/fetchers/file.c +++ b/content/fetchers/file.c @@ -256,7 +256,7 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx, { #ifdef HAVE_MMAP fetch_msg msg; - char *buf; + char *buf = NULL; size_t buf_size; int fd; /**< The file descriptor of the object */ @@ -279,17 +279,17 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx, /* set buffer size */ buf_size = fdstat->st_size; - if (buf_size > FETCH_FILE_MAX_BUF_SIZE) - buf_size = FETCH_FILE_MAX_BUF_SIZE; /* allocate the buffer storage */ - buf = mmap(NULL, buf_size, PROT_READ, MAP_SHARED, fd, 0); - if (buf == MAP_FAILED) { - msg.type = FETCH_ERROR; - msg.data.error = "Unable to map memory for file data buffer"; - fetch_file_send_callback(&msg, ctx); - close(fd); - return; + if (buf_size > 0) { + buf = mmap(NULL, buf_size, PROT_READ, MAP_SHARED, fd, 0); + if (buf == MAP_FAILED) { + msg.type = FETCH_ERROR; + msg.data.error = "Unable to map memory for file data buffer"; + fetch_file_send_callback(&msg, ctx); + close(fd); + return; + } } /* fetch is going to be successful */ @@ -327,7 +327,8 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx, fetch_file_process_aborted: - munmap(buf, buf_size); + if (buf != NULL) + munmap(buf, buf_size); close(fd); #else fetch_msg msg; |