Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a memory leak during fsm_determinise_with_config's early exit #504

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

silentbicycle
Copy link
Collaborator

  • Add a tests/regressions directory for test cases that need a standalone C file, because they aren't easily reproducible via fsm, re, etc. input files.
  • Add a test case that exercises fsm_determinise_with_config's early exit due to the state limit. When run with LeakSanitizer or Valgrind and with the previous commit reverted, it will show that the edge sets for the DFA being constructed weren't freed properly.
  • Explicitly set m->edges to NULL when transferring ownership from the stack/map to the DFA, and free any edge sets in the cleanup handler that are still in the map.

The edge sets leak when halting with FSM_DETERMINISE_WITH_CONFIG_STATE_LIMIT_REACHED.
I verified that LeakSanitizer catches the leak during this test when the
fix is reverted.

This commit adds a test directory, `tests/regressions`, for misc.
regression tests that need a .c file and aren't easily testable via fsm,
re, etc. inputs.
#include <fsm/fsm.h>
#include <fsm/bool.h>

static const char *strings[] = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input here is arbitrary, but one easy way to make a FSM whose state count increases significantly during determinisation is to combine several unanchored patterns.

Copy link
Owner

@katef katef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@katef katef merged commit 3cf9ee7 into main Nov 12, 2024
346 checks passed
@katef katef deleted the sv/fix-memory-leak-from-determinise-with-config branch November 12, 2024 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants