strace: Handle ofile descriptor more carefully.

Fix coverity CIDs 128250 - 128252

        * strace.cc (main2): Don't call setvbuf on NULL descriptor.
        Explicitely fclose ofile.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2015-08-03 12:02:17 +02:00
parent 6fc911071f
commit fe24411770
2 changed files with 13 additions and 6 deletions

View File

@ -1,3 +1,8 @@
2015-08-03 Corinna Vinschen <corinna@vinschen.de>
* strace.cc (main2): Don't call setvbuf on NULL descriptor.
Explicitely fclose ofile.
2015-07-29 Corinna Vinschen <corinna@vinschen.de>
* strace.cc (main2): Rename from main.

View File

@ -1034,6 +1034,7 @@ main2 (int argc, char **argv)
int opt;
int toggle = 0;
int sawquiet = -1;
DWORD ret = 0;
if (load_cygwin ())
{
@ -1147,23 +1148,24 @@ character #%d.\n", optarg, (int) (endptr - optarg), endptr);
if (!mask)
mask = _STRACE_ALL;
if (bufsize)
setvbuf (ofile, (char *) alloca (bufsize), _IOFBF, bufsize);
if (!ofile)
ofile = stdout;
if (bufsize)
setvbuf (ofile, (char *) alloca (bufsize), _IOFBF, bufsize);
if (toggle)
dotoggle (pid);
else
{
drive_map = (void *) cygwin_internal (CW_ALLOC_DRIVE_MAP);
DWORD ret = dostrace (mask, ofile, pid, argv + optind);
ret = dostrace (mask, ofile, pid, argv + optind);
if (drive_map)
cygwin_internal (CW_FREE_DRIVE_MAP, drive_map);
ExitProcess (ret);
}
return 0;
if (ofile && ofile != stdout)
fclose (ofile);
ExitProcess (ret);
}
int