Bug#522082: tla: file descriptor leak, causes panic when removing temporary directory
When computing a changeset (e.g. for the "tla changes --diffs" command), tla
creates a temporary directory with a name that begins in ,,what-changed.
This directory is cleaned up at the end of the operation.
Symbolic links are compared by writing the target of the link into a
text file under that directory, then relying on usual "diff" behaviour.
Unfortunately, tla doesn't explicitly close this text file. As a result:
(1) it uses more file descriptors than necessary;
(2) on some filesystems (e.g., OpenAFS 1.4.8 and newer) tla dies with
an I/O panic as the rmdir() operation on the parent directory fails with
ENOTEMPTY, even though the unlink() of the file itself succeeded, because
the file is still open.
The attached patch has been tested and gets rid of symptom (2). I expect
it to help with (1) as well. The variables that hold the file descriptor
numbers go out of scope shortly afterwards.
#! /bin/sh /usr/share/dpatch/dpatch-run
## 07-changeset-fd-leak.dpatch by Sergio Gelato <Sergio.Gelato@astro.su.se>
## All lines beginning with `## DP:' are a description of the patch.
## DP: Remember to close file descriptors before they go out of scope.
diff -urNad tla-1.3.5+dfsg-14~/src/tla/libarch/make-changeset.c tla-1.3.5+dfsg-14/src/tla/libarch/make-changeset.c
--- tla-1.3.5+dfsg-14~/src/tla/libarch/make-changeset.c 2006-07-20 08:34:40.000000000 +0200
+++ tla-1.3.5+dfsg-14/src/tla/libarch/make-changeset.c 2009-03-31 00:19:39.449388785 +0200
@@ -1485,6 +1485,9 @@
safe_printfmt (orig_out_fd, "%s\n", orig_target);
safe_printfmt (mod_out_fd, "%s\n", mod_target);
+ safe_close (orig_out_fd);
+ safe_close (mod_out_fd);
lim_free (0, patch_basename_path);
lim_free (0, orig_patch);
lim_free (0, mod_patch);