]> granicus.if.org Git - apache/commitdiff
Stop copying file names that we get from apr_file_t's and apr_dir_t's.
authorRyan Bloom <rbb@apache.org>
Fri, 5 Jan 2001 19:40:05 +0000 (19:40 +0000)
committerRyan Bloom <rbb@apache.org>
Fri, 5 Jan 2001 19:40:05 +0000 (19:40 +0000)
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

CHANGES
modules/dav/fs/repos.c
modules/generators/mod_autoindex.c
modules/mappers/mod_negotiation.c
modules/mappers/mod_speling.c
modules/test/mod_autoindex.c
server/config.c

diff --git a/CHANGES b/CHANGES
index e9526ee1efde76482ab94601e7616f1708a737b5..0b8f555366c3bfa4910c55461cdee7b6bc2368fd 100644 (file)
--- 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]
 
index d3f89e70412fefe409e08dd0ff76647e384d4708..5ec98bb0c7c9e8411df1530b8ca5596d7a24124d 100644 (file)
@@ -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);
index fc53e47ffee94c41e92eeea0a892598fbaf8e806..af4094840b731d9163e895631d7c9349206da93d 100644 (file)
@@ -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);
index 99525020c5ebca7e0110a51e5baa81a99e10168e..52a97168a8d3ea27f0932a7b4b0620b126e63126 100644 (file)
@@ -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? */
index 81f4cee242c982c92c3aaf7bbdc84f4c2dc5b23e..82e9066855f84406bf9146ab0f1b8821a73f19b0 100644 (file)
@@ -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
index 1be1080d8104a49a74f5cc9a83c76f703e728f74..b1a5b6bb7485011b9029390c0d0964dfd76f2d6a 100644 (file)
@@ -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);
index d7877ff4232bb0a848eacbe12a2090e7e2e02ac3..ef965720336d2ec9816d9871e59b5594136b7d25 100644 (file)
@@ -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, ".") &&