[LTP] [PATCH v5] open: fix cleanup condition and use snprintf

Andrea Cervesato andrea.cervesato@suse.com
Wed Mar 25 16:48:07 CET 2026


Hi Jinseok,

> static void cleanup(void)
> {
>-	if (!first || !fds)
>-		return;
>+	if (first >= 0) {
>+		int limit = fds_limit - first;
>
>+		for (int i = 0; i < limit; i++) {
>+			if (fds[i] != -1)
>+				SAFE_CLOSE(fds[i]);
>+		}
>+	}
>
>-	if (fds)
>-		free(fds);
>+	free(fds);

If SAFE_MALLOC() fails, the fds == NULL and we have a wrong memory
access. Please change the condition to:

	if (first >= 0 && fds) {

> static int *fds;
> static char fname[20];

This was pre-existing and I didn't noticed. We should use PATH_MAX
in here, instead of a pre-defined length.

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


More information about the ltp mailing list