]> git.kaiwu.me - nginx.git/commitdiff
Core: fixed default log initialization.
authorVladimir Homutov <vl@nginx.com>
Thu, 24 Jul 2014 12:25:07 +0000 (16:25 +0400)
committerVladimir Homutov <vl@nginx.com>
Thu, 24 Jul 2014 12:25:07 +0000 (16:25 +0400)
The ngx_log_insert() function may invalidate pointer passed to it,
so make sure to don't use it after the ngx_log_insert() call.

src/core/ngx_log.c

index 375d52f65d4cfcb5523718161e7c76344ea93faa..005d9ff88dcfd7d038ecd7bb5538589f573295a2 100644 (file)
@@ -387,20 +387,22 @@ ngx_log_open_default(ngx_cycle_t *cycle)
             return NGX_ERROR;
         }
 
-        log->log_level = NGX_LOG_ERR;
-        ngx_log_insert(&cycle->new_log, log);
-
     } else {
         /* no error logs at all */
         log = &cycle->new_log;
-        log->log_level = NGX_LOG_ERR;
     }
 
+    log->log_level = NGX_LOG_ERR;
+
     log->file = ngx_conf_open_file(cycle, &error_log);
     if (log->file == NULL) {
         return NGX_ERROR;
     }
 
+    if (log != &cycle->new_log) {
+        ngx_log_insert(&cycle->new_log, log);
+    }
+
     return NGX_OK;
 }