summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorChristophe Jaillet <jailletc36@apache.org>2013-03-27 22:57:44 +0100
committerChristophe Jaillet <jailletc36@apache.org>2013-03-27 22:57:44 +0100
commit86087766c6c1922f9213dbbf1b339c71d102b2c9 (patch)
tree73a656a48b5498c29ced2551fc8ae1d9d291cbca /server
parentupdate w/ correct patch level (diff)
downloadapache2-86087766c6c1922f9213dbbf1b339c71d102b2c9.tar.xz
apache2-86087766c6c1922f9213dbbf1b339c71d102b2c9.zip
Be more clever when allocating memory for log item to be escaped.
This should save about 70-100 bytes in the request pool with the default config. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1461869 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server')
-rw-r--r--server/util.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/server/util.c b/server/util.c
index 46741dd8b1..d332c38990 100644
--- a/server/util.c
+++ b/server/util.c
@@ -1850,12 +1850,26 @@ AP_DECLARE(char *) ap_escape_logitem(apr_pool_t *p, const char *str)
char *ret;
unsigned char *d;
const unsigned char *s;
+ int length = 0;
if (!str) {
return NULL;
}
- ret = apr_palloc(p, 4 * strlen(str) + 1); /* Be safe */
+ /* First, compute the space needed for the escaped string.
+ * This could be tweaked a bit for '\b', '\n'... These characters
+ * should not be common, so do not bother. */
+ s = (const unsigned char *)str;
+ for (; *s; ++s) {
+ if (TEST_CHAR(*s, T_ESCAPE_LOGITEM)) {
+ length += 4; /* for '\\' + c2x() */
+ }
+ else {
+ length++;
+ }
+ }
+
+ ret = apr_palloc(p, length + 1);
d = (unsigned char *)ret;
s = (const unsigned char *)str;
for (; *s; ++s) {