[newlib-cygwin] pldd: Fix resource leak and missing check if fopen failed

Corinna Vinschen corinna@sourceware.org
Mon Oct 24 09:25:00 GMT 2016


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=bb7ad4ed647137404bd17f876b02d0a2fc5fd807

commit bb7ad4ed647137404bd17f876b02d0a2fc5fd807
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Sun Oct 23 17:22:34 2016 +0200

    pldd: Fix resource leak and missing check if fopen failed
    
    Fixes Coverity CID 66903
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/utils/pldd.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/winsup/utils/pldd.c b/winsup/utils/pldd.c
index f977419..f077e63 100644
--- a/winsup/utils/pldd.c
+++ b/winsup/utils/pldd.c
@@ -115,12 +115,16 @@ main (int argc, char *argv[])
   if (!fd)
     error (1, ENOENT, "cannot open /proc/%d", pid);
   fscanf (fd, "%d", &winpid);
+  fclose (fd);
 
   exefile = (char *) malloc (32);
   exename = (char *) malloc (MAX_PATH);
   sprintf (exefile, "/proc/%d/exename", pid);
   fd = fopen (exefile, "rb");
+  if (!fd)
+    error (1, ENOENT, "cannot open /proc/%d", pid);
   fscanf (fd, "%s", exename);
+  fclose (fd);
 
   hProcess = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
 			  0, winpid);



More information about the Cygwin-cvs mailing list