4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-22 08:46:17 +08:00

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> 2015-07-29 Corinna Vinschen <corinna@vinschen.de>
* strace.cc (main2): Rename from main. * strace.cc (main2): Rename from main.

View File

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