[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Fix possible leaking of temporary file

From: Erik Huelsmann <e.huelsmann_at_gmx.net>
Date: 2003-12-10 20:07:36 CET

The fix below is what I currently propose. Can I commit this, or should I
pursue the more elegant version which needs APR changes? (see below)

If the WIN32 version of APR was changed to not-use
FILE_FLAG_DELETE_ON_CLOSE, but remove the file itself as the Unix variant does, it would be possible
to clear the flag before closing the file. In that case (almost) all errors
below could be handled with SVN_ERR ()...

Log:
[[[
Fix possible leaking of temporary file.

* subversion/libsvn_subr/subst.c (svn_subst_copy_and_translate): Eliminate
  possible leaking of temporary file.
]]]

Index: subversion/libsvn_subr/subst.c
===================================================================
--- subversion/libsvn_subr/subst.c (revision 7967)
+++ subversion/libsvn_subr/subst.c (working copy)
@@ -735,33 +735,35 @@
                                     eol_str, repair, keywords, expand);
 
   if (err)
- {
- /* ignore closure errors if we're bailing. */
- svn_error_clear (svn_stream_close (src_stream));
- svn_error_clear (svn_stream_close (dst_stream));
- if (s)
- apr_file_close (s);
- if (d)
- apr_file_close (d);
+ goto error;
 
- svn_error_clear (svn_io_remove_file (dst_tmp, pool));
- return
- svn_error_createf (err->apr_err, err,
- "File translation failed when copying '%s' to
'%s'",
- src, dst);
- }
-
   /* clean up nicely. */
- SVN_ERR (svn_stream_close (src_stream));
- SVN_ERR (svn_stream_close (dst_stream));
+ err = svn_stream_close (src_stream);
+ if (err)
+ goto error;
 
- SVN_ERR (svn_io_file_close (s, pool));
- SVN_ERR (svn_io_file_close (d, pool));
+ err = svn_stream_close (dst_stream);
+ if (err)
+ goto error;
 
+ err = svn_io_file_close (s, pool);
+ if (err)
+ goto error;
+
+ err = svn_io_file_close (d, pool);
+ if (err)
+ goto error;
+
   /* Now that dst_tmp contains the translated data, do the atomic rename.
*/
- SVN_ERR (svn_io_file_rename (dst_tmp, dst, pool));
+ err = svn_io_file_rename (dst_tmp, dst, pool);
+ if (err)
+ goto error;
 
   return SVN_NO_ERROR;
+ error:
+ svn_error_clear (svn_io_remove_file (dst_tmp, pool));
+
+ return err;
 }
 
 

-- 
+++ GMX - die erste Adresse für Mail, Message, More +++
Neu: Preissenkung für MMS und FreeMMS! http://www.gmx.net
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Dec 10 20:08:15 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.