Skip to content

Adding Valgrind workflow for GitHub Actions#146

Open
sjoblomj wants to merge 8 commits into
thegraydot:mainfrom
sjoblomj:valgrind_workflow
Open

Adding Valgrind workflow for GitHub Actions#146
sjoblomj wants to merge 8 commits into
thegraydot:mainfrom
sjoblomj:valgrind_workflow

Conversation

@sjoblomj

@sjoblomj sjoblomj commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

This PR adds support for Valgrind, a memory leak detector.

The PR also adds tests for the about and version subcommands. While those tests are pretty useless in themselves, they do complete the test suite for all subcommands, which also means Valgrind gets to check all subcommands.

The PR adds

  • Github Actions Workflow, that runs Valgrind on every PR, and automatically posts a comment when there are memory leaks in it.
  • Convenience script for running Valgrind locally in Docker.
  • Tests for the about and version subcommands.

Convenience script

This will setup Valgrind in Docker, run the whole test suite and check for memory leaks in the code paths that the test suite covers:

./scripts/run_valgrind_tests.sh --docker

Running a specific command

One can also invoke Valgrind for a specific command (in this case mpqcli list wow-patch.mpq):

# Build image
docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) -t mpqcli-valgrind -f Dockerfile.valgrind .

# Run image against the list subcommand and the wow-patch.mpq file
docker run --rm \
  -v $(pwd)/path/to/directory/with/test/mpqs:/mpqcli/test/data:ro \
  mpqcli-valgrind \
  valgrind --leak-check=full --show-leak-kinds=all \
  ./build/bin/mpqcli list wow-patch.mpq

(I created this PR using AI - it all seems sensible to me, but I am not an expert at either Valgrind nor GitHub Actions Workflows)

@sjoblomj sjoblomj marked this pull request as draft March 2, 2026 09:33
@sjoblomj sjoblomj force-pushed the valgrind_workflow branch 4 times, most recently from 3b2e88d to 7398f8a Compare March 3, 2026 10:14
@sjoblomj sjoblomj marked this pull request as ready for review March 3, 2026 10:31
@sjoblomj

sjoblomj commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

One of the steps in the GitHub Workflow will post comments on the PR if it contains memory leaks. But it currently does not have permissions to do so. You'll need to grant those permissions to the repo. AI says:

  1. Go to your repository on GitHub: https://github.com/TheGrayDot/mpqcli
  2. Click Settings (top right)
  3. In the left sidebar, click Actions → General
  4. Scroll down to Workflow permissions
  5. Select "Read and write permissions" (instead of "Read repository contents and packages permissions")
  6. Check the box "Allow GitHub Actions to create and approve pull requests"
  7. Click Save

Comment thread README.md Outdated
@thomaslaurenson

Copy link
Copy Markdown
Collaborator

Hey @sjoblomj - sorry for the late reply. I haven't had time to look at this PR yet. I would like to set up Valgrind locally and do some testing before I review - hope that is OK.

@sjoblomj sjoblomj force-pushed the valgrind_workflow branch from 7398f8a to fbb26de Compare June 5, 2026 07:13
@sjoblomj sjoblomj force-pushed the valgrind_workflow branch from fbb26de to 8a15946 Compare June 8, 2026 06:39
@sjoblomj

Copy link
Copy Markdown
Contributor Author

@thomaslaurenson: I gave this PR some more attention, and I think it is leaner and cleaner than before.

A comment will be automatically created in the PR when there are memory leaks. As I described in an earlier comment, you'd need to set up permissions for that to happen.

As it stands now, the checks are failing because of lack of permissions, and because there are memory leaks in the code base. PR #173 fixes the latter.

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.

2 participants