]> granicus.if.org Git - apache/commitdiff
Rearranged the log_request_time() code to eliminate the allocation
authorBrian Pane <brianp@apache.org>
Sun, 6 Jan 2002 21:03:51 +0000 (21:03 +0000)
committerBrian Pane <brianp@apache.org>
Sun, 6 Jan 2002 21:03:51 +0000 (21:03 +0000)
of an 8KB buffer on the stack when not using a custom time format

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92758 13f79535-47bb-0310-9956-ffa450edef68

modules/loggers/mod_log_config.c

index b5b15a3718de44d52e4249ab46507295b891f63f..0b86f7df7424799caa4a0204706313d0cc2bb23f 100644 (file)
@@ -446,10 +446,18 @@ static const char *log_cookie(request_rec *r, char *a)
     return NULL;
 }
 
+static const char *log_request_time_custom(request_rec *r, char *a,
+                                           apr_exploded_time_t *xt)
+{
+    apr_size_t retcode;
+    char tstr[MAX_STRING_LEN];
+    apr_strftime(tstr, &retcode, sizeof(tstr), a, xt);
+    return apr_pstrdup(r->pool, tstr);
+}
+
 static const char *log_request_time(request_rec *r, char *a)
 {
     apr_exploded_time_t xt;
-    apr_size_t retcode;
 
     /*
        hi.  i think getting the time again at the end of the request
@@ -468,9 +476,13 @@ static const char *log_request_time(request_rec *r, char *a)
     ap_explode_recent_localtime(&xt, r->request_time);
 #endif
     if (a && *a) {              /* Custom format */
-        char tstr[MAX_STRING_LEN];
-        apr_strftime(tstr, &retcode, sizeof(tstr), a, &xt);
-        return apr_pstrdup(r->pool, tstr);
+        /* The custom time formatting uses a very large temp buffer
+         * on the stack.  To avoid using so much stack space in the
+         * common case where we're not using a custom format, the code
+         * for the custom format in a separate function.  (That's why
+         * log_request_time_custom is not inlined right here.)
+         */
+        return log_request_time_custom(r, a, &xt);
     }
     else {                      /* CLF format */
        char sign;