apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/file_io/unix filedup.c
Date Wed, 19 Mar 2003 02:26:34 GMT
wrowe       2003/03/18 18:26:34

  Modified:    file_io/unix filedup.c
  Log:
    Fix bug #4 of the evening; it is altogether possible for the user to have
    called apr_file_close() against the original handle, and then invoke
    apr_file_dup2().  However, in that case the apr_file_t has already been
    unregistered from the cleanups.
  
    Always register a cleanup within _file_dup(), yet kill any remaining
    cleanup for the existing apr_file_t in the apr_file_dup2() situation.
    This also prevents double-registration, but in a more robust manner.
  
  Revision  Changes    Path
  1.57      +13 -9     apr/file_io/unix/filedup.c
  
  Index: filedup.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/unix/filedup.c,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- filedup.c	19 Mar 2003 02:16:37 -0000	1.56
  +++ filedup.c	19 Mar 2003 02:26:34 -0000	1.57
  @@ -122,6 +122,9 @@
        */
       (*new_file)->flags = old_file->flags & ~APR_INHERIT;
   
  +    apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file),
  +                              apr_unix_file_cleanup, apr_unix_file_cleanup);
  +
       return APR_SUCCESS;
   }
   
  @@ -131,21 +134,22 @@
       apr_status_t rv;
   
       rv = _file_dup(new_file, old_file, p, 1);
  -    if (rv != APR_SUCCESS)
  -        return rv;
  -
  -    /* we do this here as we don't want to double register an existing 
  -     * apr_file_t for cleanup
  -     */
  -    apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file),
  -                              apr_unix_file_cleanup, apr_unix_file_cleanup);
       return rv;
  -
   }
   
   APR_DECLARE(apr_status_t) apr_file_dup2(apr_file_t *new_file,
                                           apr_file_t *old_file, apr_pool_t *p)
   {
  +    apr_status_t rv;
  +
  +    /* an existing apr_file_t may already be closed, and therefore
  +     * have no cleanup remaining; but we don't want to double-register
  +     * the same cleanup in _file_dup.  Kill the existing cleanup before
  +     * invoking _file_dup to the existing new_file.
  +     */
  +    apr_pool_cleanup_kill(new_file->pool, (void *)(new_file),
  +                          apr_unix_file_cleanup);
  +
       return _file_dup(&new_file, old_file, p, 2);
   }
   
  
  
  

Mime
View raw message