httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1204599 - /httpd/httpd/trunk/modules/cache/mod_cache_disk.c
Date Mon, 21 Nov 2011 17:06:15 GMT
Author: minfrin
Date: Mon Nov 21 17:06:15 2011
New Revision: 1204599

URL: http://svn.apache.org/viewvc?rev=1204599&view=rev
Log:
mod_cache_disk: Make sure we check return codes on all writes and attempts
to close, and clean up after ourselves in these cases. PR43589.

Modified:
    httpd/httpd/trunk/modules/cache/mod_cache_disk.c

Modified: httpd/httpd/trunk/modules/cache/mod_cache_disk.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_cache_disk.c?rev=1204599&r1=1204598&r2=1204599&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_cache_disk.c (original)
+++ httpd/httpd/trunk/modules/cache/mod_cache_disk.c Mon Nov 21 17:06:15 2011
@@ -969,23 +969,47 @@ static apr_status_t write_headers(cache_
 
             if (rv != APR_SUCCESS) {
                 ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
-                        "cache_disk: could not create temp file %s",
+                        "cache_disk: could not create vary file %s",
                         dobj->vary.tempfile);
                 return rv;
             }
 
             amt = sizeof(format);
-            apr_file_write(dobj->vary.tempfd, &format, &amt);
+            rv = apr_file_write(dobj->vary.tempfd, &format, &amt);
+            if (rv != APR_SUCCESS) {
+                ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
+                        "cache_disk: could not write to vary file %s",
+                        dobj->vary.tempfile);
+                apr_file_close(dobj->vary.tempfd);
+                apr_pool_destroy(dobj->vary.pool);
+                return rv;
+            }
 
             amt = sizeof(h->cache_obj->info.expire);
-            apr_file_write(dobj->vary.tempfd, &h->cache_obj->info.expire, &amt);
+            rv = apr_file_write(dobj->vary.tempfd, &h->cache_obj->info.expire,
+                    &amt);
+            if (rv != APR_SUCCESS) {
+                ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
+                        "cache_disk: could not write to vary file %s",
+                        dobj->vary.tempfile);
+                apr_file_close(dobj->vary.tempfd);
+                apr_pool_destroy(dobj->vary.pool);
+                return rv;
+            }
 
             varray = apr_array_make(r->pool, 6, sizeof(char*));
             tokens_to_array(r->pool, tmp, varray);
 
             store_array(dobj->vary.tempfd, varray);
 
-            apr_file_close(dobj->vary.tempfd);
+            rv = apr_file_close(dobj->vary.tempfd);
+            if (rv != APR_SUCCESS) {
+                ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
+                        "cache_disk: could not close vary file %s",
+                        dobj->vary.tempfile);
+                apr_pool_destroy(dobj->vary.pool);
+                return rv;
+            }
 
             tmp = regen_key(r->pool, dobj->headers_in, varray, dobj->name);
             dobj->prefix = dobj->hdrs.file;
@@ -1002,7 +1026,7 @@ static apr_status_t write_headers(cache_
 
     if (rv != APR_SUCCESS) {
        ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
-                "cache_disk: could not create temp file %s",
+                "cache_disk: could not create header file %s",
                 dobj->hdrs.tempfile);
         return rv;
     }
@@ -1034,6 +1058,7 @@ static apr_status_t write_headers(cache_
                 "cache_disk: could not write info to header file %s",
                 dobj->hdrs.tempfile);
         apr_file_close(dobj->hdrs.tempfd);
+        apr_pool_destroy(dobj->hdrs.pool);
         return rv;
     }
 
@@ -1044,6 +1069,7 @@ static apr_status_t write_headers(cache_
                     "cache_disk: could not write out-headers to header file %s",
                     dobj->hdrs.tempfile);
             apr_file_close(dobj->hdrs.tempfd);
+            apr_pool_destroy(dobj->hdrs.pool);
             return rv;
         }
     }
@@ -1057,11 +1083,19 @@ static apr_status_t write_headers(cache_
                     "cache_disk: could not write in-headers to header file %s",
                     dobj->hdrs.tempfile);
             apr_file_close(dobj->hdrs.tempfd);
+            apr_pool_destroy(dobj->hdrs.pool);
             return rv;
         }
     }
 
-    apr_file_close(dobj->hdrs.tempfd); /* flush and close */
+    rv = apr_file_close(dobj->hdrs.tempfd); /* flush and close */
+    if (rv != APR_SUCCESS) {
+        ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
+                "cache_disk: could not close header file %s",
+                dobj->hdrs.tempfile);
+        apr_pool_destroy(dobj->hdrs.pool);
+        return rv;
+    }
 
     return APR_SUCCESS;
 }
@@ -1209,7 +1243,12 @@ static apr_status_t store_body(cache_han
         const char *cl_header = apr_table_get(r->headers_out, "Content-Length");
 
         if (dobj->data.tempfd) {
-            apr_file_close(dobj->data.tempfd);
+            rv = apr_file_close(dobj->data.tempfd);
+            if (rv != APR_SUCCESS) {
+                /* Buffered write failed, abandon attempt to write */
+                apr_pool_destroy(dobj->data.pool);
+                return rv;
+            }
         }
 
         if (r->connection->aborted || r->no_cache) {



Mime
View raw message