You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@hyperreal.org on 2000/01/03 21:57:29 UTC

cvs commit: apache-2.0/src/lib/apr/file_io/unix filestat.c

rbb         00/01/03 12:57:25

  Modified:    src/lib/apr/file_io/unix filestat.c
  Log:
  Fix the ap_stat function so we don't leak memory if we are passed an already
  filled out file structure.  This leaves us vulnerable to having a file
  structure where the information isn't for the file the strcture points to,
  but I think that's better than constantly allocating memory and possibly
  leaking.
  
  Revision  Changes    Path
  1.4       +10 -5     apache-2.0/src/lib/apr/file_io/unix/filestat.c
  
  Index: filestat.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/filestat.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- filestat.c	2000/01/03 19:47:43	1.3
  +++ filestat.c	2000/01/03 20:57:20	1.4
  @@ -98,13 +98,18 @@
       int rv = stat(fname, &info);
   
       if (rv == 0) {
  -        (*thefile) = ap_pcalloc(cont, sizeof(struct file_t));
           if ((*thefile) == NULL) {
  -            return APR_ENOMEM;
  +            /* Only allocate more space and initialize the object if it is
  +             * NULL when passed in.
  +             */ 
  +            (*thefile) = ap_pcalloc(cont, sizeof(struct file_t));
  +            if ((*thefile) == NULL) {
  +                return APR_ENOMEM;
  +            }
  +            (*thefile)->fname = ap_pstrdup(cont, fname);
  +            (*thefile)->filehand = NULL;
  +            (*thefile)->filedes = -1;
           }
  -        (*thefile)->fname = ap_pstrdup(cont, fname);
  -        (*thefile)->filehand = NULL;
  -        (*thefile)->filedes = -1;
           (*thefile)->protection = info.st_mode;
           (*thefile)->user = info.st_uid;
           (*thefile)->group = info.st_gid;