[LTP] [PATCH v2] msync04.c: Use direct IO to verify the data is stored on disk

Petr Vorel pvorel@suse.cz
Fri Jun 14 14:51:16 CEST 2024


Hi Wei,

...
> +static void verify_mmaped(void)
> +{
> +	char *buffer = SAFE_MEMALIGN(getpagesize(), getpagesize());
> +
> +	tst_res(TINFO, "Haven't seen dirty bit so we check content of file instead");
> +	test_fd = SAFE_OPEN("msync04/testfile", O_RDONLY | O_DIRECT);
If this fails we have memory leak, because free() is not run.

> +	SAFE_READ(0, test_fd, buffer, getpagesize());
Also here. Maybe create buf as static and have conditional free() also at the
cleanup?

Kind regards,
Petr

> +
> +	if (buffer[8] == 'B')
> +		tst_res(TCONF, "Write was too fast, couldn't test msync()");
> +	else
> +		tst_res(TFAIL, "write file failed");
> +
> +	free(buffer);
> +}
> +


More information about the ltp mailing list