Re: [PATCH] tools/counter: close fd when exit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tue, Sep 03, 2024 at 04:01:21PM +0800, zhangjiao2 kirjoitti:
> From: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>
> 
> close fd when exit the program

Please, mind English grammar and punctuation.
Also this doesn't state what the problem is.

...

>  		if (ret == -1) {
>  			fprintf(stderr, "Error adding watches[%d]: %s\n", i,
>  				strerror(errno));
> +			close(fd);

Since fd is not used in the messaging it's better to close it before printing
anything. Ditto for other cases.

...

>  		if (ret != sizeof(event_data)) {
>  			fprintf(stderr, "Failed to read event data\n");
> +			close(fd);

>  			return -EIO;

Side note: This will return garbage to the userspace. Should be

			return EIO;

>  		}

-- 
With Best Regards,
Andy Shevchenko






[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux