Skip to content

Fix errors reported by valgrind#827

Open
gottfriedleibniz wants to merge 10 commits intoSDL-Hercules-390:developfrom
gottfriedleibniz:fix/valgrind
Open

Fix errors reported by valgrind#827
gottfriedleibniz wants to merge 10 commits intoSDL-Hercules-390:developfrom
gottfriedleibniz:fix/valgrind

Conversation

@gottfriedleibniz
Copy link
Copy Markdown

@gottfriedleibniz gottfriedleibniz commented Apr 7, 2026

This PR investigated running Hercules on the test suite, VM/370 Community Edition, etc., under a variety of valgrind (mainly memcheck) configurations. To quickly reproduce these findings, func_exec_program_core in the libtool script can be modified, e.g:

exec valgrind -s --track-origins=yes --leak-check=full --show-leak-kinds=all --keep-debuginfo=yes --log-file=valgrind_out.txt "$progdir/$program" ${1+"$@"}

Much of my testing was surface-level, and I did not thoroughly exhaust all code paths, features, or interactions (esp. around networking or long-running scenarios that perform meaningful work). There may be more wins available1.

A few changes in this PR can be implemented differently, e.g., see 'cckddasd.c: ensure dasdsfn is free'd', so care is required.

Footnotes

  1. If this PR remains open for a longer period, I’ll include additional findings here. Valgrind slows things down considerably, which makes testing anything real-world a bit frustrating (I haven’t discovered anything meaningful with ASan yet).

'pszTUNDevice = strdup( DEF_NETDEV );' is definitely lost.
pszOATFilename check included to follow convention.
1. ckd_dasd_init_handler invokes cckd_sf_parse_sfn
2. ckd_dasd_init_handler invokes ckd64_dasd_init_handler
3. ckd64_dasd_init_handler invokes cckd_sf_parse_sfn

Leaving previous dasdsfn dangling. Given how 'dasdsfn' is managed (e.g.,
in attach_device and dasd_close_device), it may be more elegant to
compare the previous dasdsfn to the current pathname and throwing a
warning if they are different.
To avoid instances of memcmp'ing random stack data with curr_psw.
ARCH_DEP( maddr_l ) may reference tlb.asb and tlb.common - ensure
newregs in program_return does not reference garbage stack data.
To avoid feeding random stack data to syscalls later on (e.g., write in
cckd64_write).
Uses of string.h functions and regexec assume the string is null
delimited. This may not be true with some _PANMSG msg uses.
When CPU_BITMAP is __uint128_t and F_CPU_BITMAP is '"%16.16"PRIX64',
random/clobbered stack data will be referenced in the associated libc
formatting routines used by fwritemsg due to the different stack
alignment requirements of the variadic arguments.
panel_command may be invoked (e.g., 'LPARNUM BASIC') prior to the panel
display thread being initialized. This can lead to history_add being
invoked prior to history_init (causing dangling pointers).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant