missing call to fclose in copyin.c

View: New views
1 Messages — Rating Filter:   Alert me  

missing call to fclose in copyin.c

by Michal Seben :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

We've received the following report from a reporter:
https://bugzilla.novell.com/show_bug.cgi?id=543132 :

--------------------
source code file cpio-2.10/src/copyin.c
function process_copy_in
local variable tty_out.

I notice the following code

      tty_out = fopen (TTY_NAME, "w");

but I fail to notice a matching call to fclose. This looks like a resource
leak to me. Suggest add call to fclose near the end of the function.
--------------------


I also attach suggested fix from Robert Schweikert

thanks



[cpio-2.10-close_files_after_copy.patch]

Index: src/copyin.c
===================================================================
--- src/copyin.c.orig
+++ src/copyin.c
@@ -1565,6 +1565,19 @@ process_copy_in ()
   if (dot_flag)
     fputc ('\n', stderr);
 
+  if (tty_in)
+    {
+      fclose(tty_in);
+    }
+  if (tty_out)
+    {
+      fclose(tty_out);
+    }
+  if (rename_in)
+    {
+      fclose(rename_in);
+    }
+
   if (append_flag)
     return;