From 8206d63ddfe5fbd4bf3d15ae9c11ab7a26e8ca4a Mon Sep 17 00:00:00 2001 From: Christophe Jaillet Date: Wed, 27 Mar 2013 21:57:44 +0000 Subject: [PATCH] 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 --- server/util.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/util.c b/server/util.c index 46741dd8b19..d332c389907 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) { -- 2.47.3