[LTP] close02: add test for double close EBADF

Andrea Cervesato andrea.cervesato@suse.com
Wed May 6 14:10:17 CEST 2026


Hi Jinseok,

The review agent is actually correct here. If we close the fd
with SAFE_CLOSE() it will end up having -1 value. You need to
use the raw close() plus checking its return value.

> Hi Jinseok,
> 
> On 2026-04-29, Jinseok Kim wrote:
> > close02: add test for double close EBADF
> 
> > +static void setup(void)
> > +{
> > +	fd_closed = SAFE_OPEN("close02", O_CREAT | O_RDWR, 0600);
> > +	SAFE_CLOSE(fd_closed);
> > +}
> 
> SAFE_CLOSE(fd_closed) resets fd_closed to -1 (the macro does `fd = -1`
> after the close), so both test cases end up calling close(-1). The second
> case never exercises the double-close path. Use a local variable to
> preserve the fd value:
> 
>     int fd = SAFE_OPEN("close02", O_CREAT | O_RDWR, 0600);
>     fd_closed = fd;
>     SAFE_CLOSE(fd);
> 
> ---
> Note:
> 
> Our agent completed the review of the patch.
> 
> The agent can sometimes produce false positives although often its
> findings are genuine. If you find issues with the review, please
> comment this email or ignore the suggestions.
> 
> Regards,
> LTP AI Reviewer
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com


More information about the ltp mailing list