pldd: Fix resource leak and missing check if fopen failed

Fixes Coverity CID 66903

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2016-10-23 17:22:34 +02:00
parent 79edb254ac
commit bb7ad4ed64
1 changed files with 4 additions and 0 deletions

View File

@ -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);