[PATCH]Upstream: delete temp file when error in ngx_http_upstream_store().

flygoast flygoast at 126.com
Mon Jul 7 09:19:45 UTC 2014


# HG changeset patch
# User FengGu <flygoast at 126.com>
# Date 1404723967 -28800
#      Mon Jul 07 17:06:07 2014 +0800
# Node ID d1d597fbf6d8e08059a308d8900e5f90def5377a
# Parent  a680bf4dddd5c4b106419e3dfb0264815c401275
Upstream: delete temp file when error in ngx_http_upstream_store().


Previously, didn't process the case when ngx_http_map_uri_to_path() returned
NULL. And when error occured, didn't delete the temp file.


diff -r a680bf4dddd5 -r d1d597fbf6d8 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.cSat Jul 05 23:29:47 2014 +0400
+++ b/src/http/ngx_http_upstream.cMon Jul 07 17:06:07 2014 +0800
@@ -3375,14 +3375,16 @@
 
     if (u->conf->store_lengths == NULL) {
 
-        ngx_http_map_uri_to_path(r, &path, &root, 0);
+        if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) {
+            goto error;
+        }
 
     } else {
         if (ngx_http_script_run(r, &path, u->conf->store_lengths->elts, 0,
                                 u->conf->store_values->elts)
             == NULL)
         {
-            return;
+            goto error;
         }
     }
 
@@ -3393,6 +3395,16 @@
                    tf->file.name.data, path.data);
 
     (void) ngx_ext_rename_file(&tf->file.name, &path, &ext);
+
+    return;
+
+error:
+
+    if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) {
+        ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
+                      ngx_delete_file_n " \"%s\" failed",
+                      tf->file.name.data);
+    }
 }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20140707/04155278/attachment.html>


More information about the nginx-devel mailing list