sox_ng/test/waveaudio-teardown/run
barstoolbluz 3963ad5864 waveaudio: keep WAVEHDR storage alive if device close fails
The driver can return MMSYSERR_STILLPLAYING when closing a device. The
old stop function ignores that result; format teardown then releases
ft->priv even though its embedded WAVEHDRs can remain driver-owned.

Check reset, unprepare and close results on both input and output. On a
failed device close, detach the private allocation from ft so the generic
format cleanup cannot release the live headers, data or callback event.
On successful close, release them normally. The failure path intentionally
retains storage for the remaining process lifetime instead of risking
use-after-free.

Extend the WinMM teardown simulation to cover close refusal, reset and
wait failures, header unprepare failures, timer rollover and the input
close path. Actual Windows device playback remains unverified.
2026-10-24 16:29:32 -04:00

23 lines
903 B
Bash
Executable file

#!/bin/sh
# Exercise the WinMM teardown with deterministic device responses.
# No Windows device is required; the tested functions come from waveaudio.c.
work=$(mktemp -d "${TMPDIR:-/tmp}/sox-waveaudio.XXXXXXXX") || exit 2
trap 'rm -rf "$work"' EXIT HUP INT TERM
awk '
/^typedef struct waveaudio_priv_t/ { in_section=1 }
/^static unsigned check_format/ { in_section=0 }
in_section { print }
' ../../src/waveaudio.c > "$work/teardown.inc"
if ! grep -q '^static int stop(' "$work/teardown.inc"; then
echo 'waveaudio teardown not found' >&2
exit 2
fi
cp winmm-driver.c "$work/driver.c"
${CC:-cc} -std=c99 -Wall -Wextra -Werror -Wno-unused-function -O1 -I"$work" \
"$work/driver.c" -o "$work/winmm-driver" || exit 2
for case in idle drain timeout tick-wrap wait-failure reset-failure unprepare-failure close-failure input-close-failure; do
"$work/winmm-driver" "$case" || exit 2
done
exit 0