ACK: [PATCH] lib: fwts_pipe: clean up static analyzer warning on freopen

Alex Hung alex.hung at canonical.com
Thu May 21 23:21:00 UTC 2015


On 05/15/2015 03:37 AM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
> 
> cppcheck is being a bit overly zealous:
> 
> [src/lib/src/fwts_pipeio.c:64]: (error) Return value of allocation function freopen is not stored.
>   (error) Return value of allocation function freopen is not stored.
> 
> ..but we may as well assign a file pointer to the freopen() call and
> explicitly close it before calling _exit() just to make things a little
> clearer to cppcheck
> 
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/lib/src/fwts_pipeio.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lib/src/fwts_pipeio.c b/src/lib/src/fwts_pipeio.c
> index b5d7fee..94edb16 100644
> --- a/src/lib/src/fwts_pipeio.c
> +++ b/src/lib/src/fwts_pipeio.c
> @@ -48,6 +48,7 @@ int fwts_pipe_open(const char *command, pid_t *childpid)
>  {
>  	int pipefds[2];
>  	pid_t pid;
> +	FILE *fp;
>  
>  	if (pipe(pipefds) < 0)
>  		return -1;
> @@ -61,7 +62,7 @@ int fwts_pipe_open(const char *command, pid_t *childpid)
>  		return -1;
>  	case 0:
>  		/* Child */
> -		if (freopen("/dev/null", "w", stderr) == NULL) {
> +		if ((fp = freopen("/dev/null", "w", stderr)) == NULL) {
>  			fprintf(stderr, "Cannot redirect stderr\n");
>  		}
>  		if (pipefds[0] != STDOUT_FILENO) {
> @@ -70,6 +71,8 @@ int fwts_pipe_open(const char *command, pid_t *childpid)
>  		}
>  		close(pipefds[0]);
>  		execl(_PATH_BSHELL, "sh", "-c", command, NULL);
> +		if (fp)
> +			fclose(fp);
>  		_exit(FWTS_EXEC_ERROR);
>  	default:
>  		/* Parent */
> 

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list