From 65c04f6b24ef2307f28e8e330f651877f864d807 Mon Sep 17 00:00:00 2001 From: Stefan Fritsch Date: Sat, 21 May 2011 21:06:15 +0000 Subject: [PATCH] Replace some "apr_p[c]alloc / memcpy" constructions into a single apr_pmemdup()s PR: 51214 Submitted by: Christophe Jaillet git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1125818 13f79535-47bb-0310-9956-ffa450edef68 --- modules/filters/mod_sed.c | 6 ++---- modules/generators/mod_cgid.c | 3 +-- modules/proxy/proxy_util.c | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/filters/mod_sed.c b/modules/filters/mod_sed.c index 8c67706093..64ff4bf80c 100644 --- a/modules/filters/mod_sed.c +++ b/modules/filters/mod_sed.c @@ -138,8 +138,7 @@ static apr_status_t flush_output_buffer(sed_filter_ctxt *ctx) apr_status_t status = APR_SUCCESS; if ((ctx->outbuf == NULL) || (size <=0)) return status; - out = apr_palloc(ctx->tpool, size); - memcpy(out, ctx->outbuf, size); + out = apr_pmemdup(ctx->tpool, ctx->outbuf, size); status = append_bucket(ctx, out, size); ctx->curoutbuf = ctx->outbuf; return status; @@ -174,8 +173,7 @@ static apr_status_t sed_write_output(void *dummy, char *buf, int sz) /* if size is bigger than the allocated buffer directly add to output * brigade */ if ((status == APR_SUCCESS) && (sz >= ctx->bufsize)) { - char* newbuf = apr_palloc(ctx->tpool, sz); - memcpy(newbuf, buf, sz); + 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) { diff --git a/modules/generators/mod_cgid.c b/modules/generators/mod_cgid.c index 5f3b2c4c88..0df7f6d13d 100644 --- a/modules/generators/mod_cgid.c +++ b/modules/generators/mod_cgid.c @@ -847,8 +847,7 @@ static int cgid_server(void *data) key = &cgid_req.conn_id; } else { - key = apr_pcalloc(pcgi, sizeof(cgid_req.conn_id)); - memcpy(key, &cgid_req.conn_id, sizeof(cgid_req.conn_id)); + key = apr_pmemdup(pcgi, &cgid_req.conn_id, sizeof(cgid_req.conn_id)); } apr_hash_set(script_hash, key, sizeof(cgid_req.conn_id), (void *)((long)procnew->pid)); diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 8339d40376..e79d84bfdb 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -2618,8 +2618,8 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function, proxy_function, backend_addr->family, worker->s->hostname); if (conf->source_address_set) { - local_addr = apr_pcalloc(conn->pool, sizeof(apr_sockaddr_t)); - memcpy(local_addr, conf->source_address, sizeof(apr_sockaddr_t)); + local_addr = apr_pmemdup(conn->pool, conf->source_address, + sizeof(apr_sockaddr_t)); local_addr->pool = conn->pool; rv = apr_socket_bind(newsock, local_addr); if (rv != APR_SUCCESS) { -- 2.40.0