bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix several missing close() calls.


From: Roman Rakus
Subject: [PATCH] Fix several missing close() calls.
Date: Thu, 24 Jan 2013 23:53:59 +0100

There are missing calls of close() leading to resource leak (fd leak).
Simple reproducer:
. /
and /proc/$$/fd contain one open fd for each above call

Signed-off-by: Roman Rakus <rrakus@redhat.com>
---
 builtins/evalfile.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/builtins/evalfile.c b/builtins/evalfile.c
index 60f89d1..d30bd96 100644
--- a/builtins/evalfile.c
+++ b/builtins/evalfile.c
@@ -133,11 +133,13 @@ file_error_and_exit:
   if (S_ISDIR (finfo.st_mode))
     {
       (*errfunc) (_("%s: is a directory"), filename);
+      close(fd);
       return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1);
     }
   else if ((flags & FEVAL_REGFILE) && S_ISREG (finfo.st_mode) == 0)
     {
       (*errfunc) (_("%s: not a regular file"), filename);
+      close(fd);
       return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1);
     }
 
@@ -146,6 +148,7 @@ file_error_and_exit:
   if (file_size != finfo.st_size || file_size + 1 < file_size)
     {
       (*errfunc) (_("%s: file is too large"), filename);
+      close(fd);
       return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1);
     }      
 
-- 
1.7.11.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]