From 68c1f5338f3ed1fdf3b177e1d7bedf5bd41fc505 Mon Sep 17 00:00:00 2001
From: Joshua Colp <jcolp@digium.com>
Date: Wed, 24 Jan 2007 00:22:50 +0000
Subject: [PATCH] Close file after we do the translation, and map memory for
 both reading/writing. (issue #8886 reported by cwegener)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@51831 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 main/manager.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/main/manager.c b/main/manager.c
index ca83f3c00e..4464d9dce2 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -2820,10 +2820,9 @@ static struct ast_str *generic_http_callback(enum output_format format,
 		char *buf;
 		size_t l = ftell(s->f);
 
-		fclose(s->f);
 		if (format == FORMAT_XML || format == FORMAT_HTML) {
 			if (l) {
-				if ((buf = mmap(NULL, l, PROT_READ, MAP_SHARED, s->fd, 0))) {
+				if ((buf = mmap(NULL, l, PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, 0))) {
 					xml_translate(&out, buf, params, format);
 					munmap(buf, l);
 				}
@@ -2831,6 +2830,7 @@ static struct ast_str *generic_http_callback(enum output_format format,
 				xml_translate(&out, "", params, format);
 			}
 		}
+		fclose(s->f);
 		s->f = NULL;
 		s->fd = -1;
 	}
-- 
GitLab