svashisht / rpms / bash

Forked from rpms/bash 4 years ago
Clone

Blame SOURCES/bash-4.2-missing_closes.patch

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

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

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