Index: main/manager.c =================================================================== --- main/manager.c (revision 320715) +++ main/manager.c (working copy) @@ -238,7 +238,6 @@ * contained within points to session-specific data. */ struct mansession { - FILE *f; struct mansession_session *session; int fd; }; @@ -2895,6 +2894,7 @@ char *c = workspace; char *retval = NULL; struct ast_variable *v; + char template[] = "/tmp/ast-httpcb-XXXXXX"; for (v = params; v; v = v->next) { if (!strcasecmp(v->name, "mansession_id")) { @@ -2942,8 +2942,9 @@ ss.session = s; ast_mutex_unlock(&s->__lock); - ss.f = tmpfile(); - ss.fd = fileno(ss.f); + if ((ss.fd = mkstemp(template)) > -1) { + unlink(template); + } if (s) { struct message m = { 0 }; @@ -2990,12 +2991,14 @@ char *buf; size_t l; + /* Make sure that our buffer is NULL terminated */ + ast_carefulwrite(ss.fd, "", 1, ss.session->writetimeout); + if ((l = lseek(ss.fd, 0, SEEK_END)) > 0) { - if (MAP_FAILED == (buf = mmap(NULL, l + 1, PROT_READ | PROT_WRITE, MAP_SHARED, ss.fd, 0))) { + if (MAP_FAILED == (buf = mmap(NULL, l, PROT_READ | PROT_WRITE, MAP_SHARED, ss.fd, 0))) { ast_log(LOG_WARNING, "mmap failed. Manager request output was not processed\n"); } else { char *tmpbuf; - buf[l] = '\0'; if (format == FORMAT_XML) tmpbuf = xml_translate(buf, params); else if (format == FORMAT_HTML) @@ -3016,11 +3019,10 @@ free(tmpbuf); free(s->outputstr); s->outputstr = NULL; - munmap(buf, l + 1); + munmap(buf, l); } } - fclose(ss.f); - ss.f = NULL; + close(ss.fd); ss.fd = -1; } else if (s->outputstr) { char *tmp;