From: Ryan Bloom Date: Fri, 5 Jan 2001 19:40:05 +0000 (+0000) Subject: Stop copying file names that we get from apr_file_t's and apr_dir_t's. X-Git-Tag: APACHE_2_0_BETA_CANDIDATE_1~270 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83c2b3f96bad0883376b667fdc67854d6f2c0ee2;p=apache Stop copying file names that we get from apr_file_t's and apr_dir_t's. We copy the data when we store it in the structures, we can just return a pointer from there, and use const data. This puts the onus back on Apache to copy the data if it needs to modify it. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87592 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index e9526ee1ef..0b8f555366 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,10 @@ Changes with Apache 2.0b1 + *) Stop returning copies of filenames from both apr_file_t and + apr_dir_t. We pstrdup the filenames that we store in the + actual structures, so we don't need to pstrdup the strings again. + [Ryan Bloom] + *) mod_cgi: Fix some problems where the wrong error value was being traced. [Jeff Trawick] diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index d3f89e7041..5ec98bb0c7 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -1357,7 +1357,7 @@ static dav_error * dav_fs_walker(dav_fs_walker_context *fsctx, int depth) return dav_new_error(pool, HTTP_NOT_FOUND, 0, NULL); } while ((apr_readdir(dirp)) == APR_SUCCESS) { - char *name; + const char *name; apr_size_t len; apr_get_dir_filename(&name, dirp); diff --git a/modules/generators/mod_autoindex.c b/modules/generators/mod_autoindex.c index fc53e47ffe..af4094840b 100644 --- a/modules/generators/mod_autoindex.c +++ b/modules/generators/mod_autoindex.c @@ -1157,7 +1157,7 @@ static char *find_title(request_rec *r) return NULL; } -static struct ent *make_autoindex_entry(char *name, int autoindex_opts, +static struct ent *make_autoindex_entry(const char *name, int autoindex_opts, autoindex_config_rec *d, request_rec *r, char keyid, char direction) @@ -1622,7 +1622,7 @@ static int index_directory(request_rec *r, */ head = NULL; while (apr_readdir(d) == APR_SUCCESS) { - char *d_name; + const char *d_name; apr_get_dir_filename(&d_name, d); p = make_autoindex_entry(d_name, autoindex_opts, autoindex_conf, r, keyid, direction); diff --git a/modules/mappers/mod_negotiation.c b/modules/mappers/mod_negotiation.c index 99525020c5..52a97168a8 100644 --- a/modules/mappers/mod_negotiation.c +++ b/modules/mappers/mod_negotiation.c @@ -938,7 +938,7 @@ static int read_types_multi(negotiation_state *neg) while (apr_readdir(dirp) == APR_SUCCESS) { request_rec *sub_req; - char *d_name; + const char *d_name; apr_get_dir_filename(&d_name, dirp); /* Do we have a match? */ diff --git a/modules/mappers/mod_speling.c b/modules/mappers/mod_speling.c index 81f4cee242..82e9066855 100644 --- a/modules/mappers/mod_speling.c +++ b/modules/mappers/mod_speling.c @@ -236,7 +236,8 @@ static int sort_by_quality(const void *left, const void *rite) static int check_speling(request_rec *r) { spconfig *cfg; - char *good, *bad, *postgood, *url, *fname; + char *good, *bad, *postgood, *url; + const char *fname; int filoc, dotloc, urlen, pglen; apr_array_header_t *candidates = NULL; apr_dir_t *dir; @@ -309,10 +310,6 @@ static int check_speling(request_rec *r) dotloc = strlen(bad); } - /* NOTE: apr_get_dir_filename() fills fname with a apr_palloc()ed copy - * of the found directory name already. We don't need to copy it. - * @@@: Copying *ALL* found file names is wasted energy (and memory)! - */ while (apr_readdir(dir) == APR_SUCCESS && apr_get_dir_filename(&fname, dir) == APR_SUCCESS) { sp_reason q; @@ -335,7 +332,7 @@ static int check_speling(request_rec *r) misspelled_file *sp_new; sp_new = (misspelled_file *) apr_push_array(candidates); - sp_new->name = fname; + sp_new->name = apr_pstrdup(r->pool, fname); sp_new->quality = SP_MISCAPITALIZED; } @@ -347,7 +344,7 @@ static int check_speling(request_rec *r) misspelled_file *sp_new; sp_new = (misspelled_file *) apr_push_array(candidates); - sp_new->name = fname; + sp_new->name = apr_pstrdup(r->pool, fname); sp_new->quality = q; } @@ -393,7 +390,7 @@ static int check_speling(request_rec *r) misspelled_file *sp_new; sp_new = (misspelled_file *) apr_push_array(candidates); - sp_new->name = fname; + sp_new->name = apr_pstrdup(r->pool, fname); sp_new->quality = SP_VERYDIFFERENT; } #endif diff --git a/modules/test/mod_autoindex.c b/modules/test/mod_autoindex.c index 1be1080d81..b1a5b6bb74 100644 --- a/modules/test/mod_autoindex.c +++ b/modules/test/mod_autoindex.c @@ -1622,7 +1622,7 @@ static int index_directory(request_rec *r, */ head = NULL; while (apr_readdir(d) == APR_SUCCESS) { - char *d_name; + const char *d_name; apr_get_dir_filename(&d_name, d); p = make_autoindex_entry(d_name, autoindex_opts, autoindex_conf, r, keyid, direction); diff --git a/server/config.c b/server/config.c index d7877ff423..ef96572033 100644 --- a/server/config.c +++ b/server/config.c @@ -1389,7 +1389,7 @@ void ap_process_resource_config(server_rec *s, const char *fname, } candidates = apr_make_array(p, 1, sizeof(fnames)); while (apr_readdir(dirp) == APR_SUCCESS) { - char *d_name; + const char *d_name; apr_get_dir_filename(&d_name, dirp); /* strip out '.' and '..' */ if (strcmp(d_name, ".") &&