]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
* Improve the logic flow
authorRuediger Pluem <rpluem@apache.org>
Tue, 8 Mar 2022 15:41:55 +0000 (15:41 +0000)
committerRuediger Pluem <rpluem@apache.org>
Tue, 8 Mar 2022 15:41:55 +0000 (15:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1898735 13f79535-47bb-0310-9956-ffa450edef68

modules/filters/mod_sed.c

index 8c940952c0a650f943cbc502ec3845b5671a1bc0..6d3f12050353a62c0514e96048d3a95f1f540e1c 100644 (file)
@@ -168,21 +168,29 @@ static apr_status_t sed_write_output(void *dummy, char *buf, apr_size_t sz)
         }
         /* buffer is now full */
         status = append_bucket(ctx, ctx->outbuf, ctx->bufsize);
-        /* old buffer is now used so allocate new buffer */
-        alloc_outbuf(ctx);
-        /* if size is bigger than the allocated buffer directly add to output
-         * brigade */
-        if ((status == APR_SUCCESS) && (sz >= ctx->bufsize)) {
-            char* newbuf = apr_pmemdup(ctx->tpool, buf, sz);
-            status = append_bucket(ctx, newbuf, sz);
-            /* pool might get clear after append_bucket */
-            if (ctx->outbuf == NULL) {
+        if (status == APR_SUCCESS) {
+            /* if size is bigger than the allocated buffer directly add to output
+             * brigade */
+            if (sz >= ctx->bufsize) {
+                char* newbuf = apr_pmemdup(ctx->tpool, buf, sz);
+                status = append_bucket(ctx, newbuf, sz);
+                if (status == APR_SUCCESS) {
+                    /* old buffer is now used so allocate new buffer */
+                    alloc_outbuf(ctx);
+                }
+                else {
+                    clear_ctxpool(ctx);
+                }
+            }
+            else {
+                /* old buffer is now used so allocate new buffer */
                 alloc_outbuf(ctx);
+                memcpy(ctx->curoutbuf, buf, sz);
+                ctx->curoutbuf += sz;
             }
         }
         else {
-            memcpy(ctx->curoutbuf, buf, sz);
-            ctx->curoutbuf += sz;
+            clear_ctxpool(ctx);
         }
     }
     else {