From cb8266e79741e2e73ddb968761e192f8c9e02508 Mon Sep 17 00:00:00 2001 From: Randall Stewart Date: Tue, 27 Jan 2015 18:56:22 +0000 Subject: [PATCH] Fix yet another coverty warning (missing io is NULL check) and in examining that warning I see yet another issue where we should be pclosing the io in the event of the error and its a command (not fclose only). --- usr.sbin/pmcstudy/pmcstudy.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/usr.sbin/pmcstudy/pmcstudy.c b/usr.sbin/pmcstudy/pmcstudy.c index a99d59a8cb33..a7ec3719a0b4 100644 --- a/usr.sbin/pmcstudy/pmcstudy.c +++ b/usr.sbin/pmcstudy/pmcstudy.c @@ -1796,6 +1796,10 @@ process_file(char *filename) if (filename == NULL) { io = my_popen(command, "r", &pid_of_command); + if (io == NULL) { + printf("Can't popen the command %s\n", command); + return; + } } else { io = fopen(filename, "r"); if (io == NULL) { @@ -1808,8 +1812,10 @@ process_file(char *filename) if (cnts == NULL) { /* Nothing we can do */ printf("Nothing to do -- no counters built\n"); - if (io) { - fclose(io); + if (filename) { + fclose(io); + } else { + my_pclose(io, pid_of_command); } return; }