[erlang-patches] Fix resource leakage in efile_openfile

Michael Santos michael.santos@REDACTED
Sat Feb 26 14:51:00 CET 2011


On Sat, Feb 26, 2011 at 12:16:49PM +0100, Tuncer Ayaz wrote:
> git fetch git://github.com/tuncer/otp.git efile-fd-leak

Hey Tuncer!

diff --git a/erts/emulator/drivers/unix/unix_efile.c b/erts/emulator/drivers/unix/unix_efile.c
index 4b39346..93568e3 100644
--- a/erts/emulator/drivers/unix/unix_efile.c
+++ b/erts/emulator/drivers/unix/unix_efile.c
@@ -741,14 +741,17 @@ efile_openfile(Efile_error* errInfo,	/* Where to return error codes. */
 	 * (see efile_mkdir)
 	 */
     if ((fd < 0) && (strchr(name, '/') != NULL) && (errno == 0xd)) {
+	close(fd);
 	/* Return the correct error code enoent */ 
 	errno = S_nfsLib_NFSERR_NOENT;
 	return check_error(-1, errInfo);
     }
 #endif
 
-    if (!check_error(fd, errInfo))
+    if (!check_error(fd, errInfo)) {
+	close(fd);
 	return 0;
+    }
 
     *pfd = fd;
     if (pSize) {


check_error() returns false if the fd is bad (-1), so the fd shouldn't
need to be closed since no resources have been allocated. Maybe the file
leak is happening somewhere else?




More information about the erlang-patches mailing list