Fix fd leaks which can cause Plymouth to exit unexpectedly.

James Hunt james.hunt at ubuntu.com
Mon Oct 10 07:27:06 PDT 2011


---
 src/client/plymouth.c                          |    1 +
 src/libply-splash-core/ply-text-progress-bar.c |    4 +++-
 src/libply/ply-logger.c                        |    4 +++-
 src/libply/ply-utils.c                         |    8 ++++++--
 src/main.c                                     |    1 +
 5 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/client/plymouth.c b/src/client/plymouth.c
index 84fe6e3..7257418 100644
--- a/src/client/plymouth.c
+++ b/src/client/plymouth.c
@@ -773,6 +773,7 @@ get_kernel_command_line (state_t *state)
   if (read (fd, state->kernel_command_line, sizeof (state->kernel_command_line)) < 0)
     {
       ply_trace ("couldn't read it: %m");
+      close (fd);
       return false;
     }
 
diff --git a/src/libply-splash-core/ply-text-progress-bar.c b/src/libply-splash-core/ply-text-progress-bar.c
index 7ac0222..faf84a4 100644
--- a/src/libply-splash-core/ply-text-progress-bar.c
+++ b/src/libply-splash-core/ply-text-progress-bar.c
@@ -106,8 +106,10 @@ get_os_string (void)
   if (fd == -1)
     return;
 
-  if (fstat (fd, &sbuf) == -1)
+  if (fstat (fd, &sbuf) == -1) {
+    close (fd);
     return;
+  }
 
   buf = calloc (sbuf.st_size + 1, sizeof(char));
   read (fd, buf, sbuf.st_size);
diff --git a/src/libply/ply-logger.c b/src/libply/ply-logger.c
index df4738f..f51bb84 100644
--- a/src/libply/ply-logger.c
+++ b/src/libply/ply-logger.c
@@ -338,8 +338,10 @@ ply_logger_open_file (ply_logger_t    *logger,
   if (fd < 0)
     return false;
 
-  if (fchmod (fd, mode) < 0)
+  if (fchmod (fd, mode) < 0) {
+    close (fd);
     return false;
+  }
 
   ply_logger_set_output_fd (logger, fd);
 
diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c
index b021f2f..07abaad 100644
--- a/src/libply/ply-utils.c
+++ b/src/libply/ply-utils.c
@@ -553,8 +553,10 @@ ply_close_open_fds (void)
 
       if ((*byte_after_number != '\0') ||
           (filename_as_number < 0) ||
-          (filename_as_number > INT_MAX)) 
+          (filename_as_number > INT_MAX)) {
+        closedir (dir);
         return false;
+      }
 
       fd = (int) filename_as_number;
 
@@ -668,8 +670,10 @@ ply_list_directory (const char *path)
   if (dir == NULL)
     return;
 
-  if (level > 5)
+  if (level > 5) {
+    closedir (dir);
     return;
+  }
 
   int index = 0;
   while ((entry = readdir (dir)) != NULL) 
diff --git a/src/main.c b/src/main.c
index dbd4d82..140df67 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1689,6 +1689,7 @@ get_kernel_command_line (state_t *state)
   if (read (fd, state->kernel_command_line, sizeof (state->kernel_command_line)) < 0)
     {
       ply_trace ("couldn't read it: %m");
+      close (fd);
       return false;
     }
 
-- 
1.7.5.4



--------------030303020209030002050601--


More information about the plymouth mailing list