[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tmpfile leaks
From: |
Chris K. Jester-Young |
Subject: |
Re: tmpfile leaks |
Date: |
Fri, 29 Jul 2011 12:04:12 -0400 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Fri, Jul 29, 2011 at 09:07:43AM +0200, Andy Wingo wrote:
> What should we do here?
There's two ways I can think of:
1. Basically reimplement the functionality of tmpfile, using mkstemp
and unlink, passing the fd to scm_fdes_to_port as before. This does
require reimplementing the TMPDIR lookup stuff (since that doesn't
seem to be exposed by libc).
2. Use tmpfile as before, dup the file descriptor, and close the stdio
stream unconditionally. This is wasteful of a file stream in that
one gets created only to be immediately destroyed, but it's more
faithful to the system-provided tmpfile, quirks and all.
In the end, I chose approach 2 (more daring coders may want to have a
go at 1 :-)). Attached is a diff.
Cheers,
Chris.
diff --git a/libguile/posix.c b/libguile/posix.c
index 2923dc6..8dea378 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1338,10 +1338,15 @@ SCM_DEFINE (scm_tmpfile, "tmpfile", 0, 0, 0,
#define FUNC_NAME s_scm_tmpfile
{
FILE *rv;
+ int fd;
if (! (rv = tmpfile ()))
SCM_SYSERROR;
- return scm_fdes_to_port (fileno (rv), "w+", SCM_BOOL_F);
+ fd = dup (fileno (rv));
+ fclose (rv);
+ if (fd == -1)
+ SCM_SYSERROR;
+ return scm_fdes_to_port (fd, "w+", SCM_BOOL_F);
}
#undef FUNC_NAME
- tmpfile leaks, Andy Wingo, 2011/07/29
- Re: tmpfile leaks,
Chris K. Jester-Young <=