Skip to content

fix typos, add tests#9

Closed
msimerson wants to merge 3 commits intoJohnKaul:mainfrom
msimerson:fix-mem-leaks
Closed

fix typos, add tests#9
msimerson wants to merge 3 commits intoJohnKaul:mainfrom
msimerson:fix-mem-leaks

Conversation

@msimerson
Copy link
Copy Markdown
Contributor

@msimerson msimerson commented Apr 29, 2026

Fixes #8 and #6

Changed in src/parse-config.c:

  • find_config_item(): Changed strncmp() to strcmp() for exact matching (line 140)
  • contains(): Changed strncmp() to strcmp() (line 183)
  • get_value(): Changed strncmp() to strcmp() (line 265)

This prevents incorrect matches like 'keymap' matching 'keymaps'.

Refactored in src/sysconf.c:

  • Fixed the logic for add/subtract operations
  • Improved how values are processed and compared
  • The operations now work correctly without creating duplicate entries

Memory leaks

  • Changed strndup() to strdup() where appropriate (less overhead)
  • Changed malloc() to calloc() for zero-initialization
  • Better error handling with goto cleanup pattern
  • Proper memory cleanup throughout

Workflow

  • added a GHA workflow, compiles the code and runs make test
    • the workflow results 👇 are a link, click to see the results

@JohnKaul and/or @pr9000, can one of you run valgrind against this? I've run leaks against it and it passes.

@msimerson msimerson marked this pull request as ready for review April 29, 2026 20:41
@msimerson msimerson changed the title fix the memory leaks, add some tests fix memory leaks, typos, adds tests Apr 29, 2026
@pr9000
Copy link
Copy Markdown
Contributor

pr9000 commented Apr 29, 2026

Hi @msimerson,

I ran the full test suite on FreeBSD 15.0-CURRENT (Clang 19.1.7), including the strict Valgrind configurations.

Results:

  • All functional tests passed (get_01–03, set_01–04)
  • The += and -= operations behave correctly and no duplicate entries were observed
  • Memory checks (valgrind --leak-check=full --show-leak-kinds=all) reported no leaks in any of the test runs
  • All strict and full validation scripts completed successfully

The changes to strcmp() for exact matching resolve the previous partial-match issue, and the updated memory handling with the cleanup pattern appears solid in testing.

Attaching the full Valgrind logs from the strict run for reference.

Log summary:
All test cases passed and no memory leaks were detected under the strict Valgrind configurations.

Thanks for the improvements — this addresses issues #8 and #6 cleanly.
test_syntax_valgrind_20260429_230201UTC.log

@JohnKaul
Copy link
Copy Markdown
Owner

JohnKaul commented May 4, 2026

I've been away the last few days but I just started looking at this. However, I've already done some refactoring which should render a bit of this PR unrelated but from a quick glance, some of these would be nice to add. I'll need to learn how to cherry pick on GitHub.

@msimerson msimerson changed the title fix memory leaks, typos, adds tests fix typos, add tests May 5, 2026
@msimerson
Copy link
Copy Markdown
Contributor Author

I've already done some refactoring which should render a bit of this PR unrelated

Great, your refactoring did solve the memory leak issues. I've rebased this against your branch so it once again merges cleanly. If you tell me which parts of this PR you don't want, I can remove them.

@JohnKaul
Copy link
Copy Markdown
Owner

JohnKaul commented May 5, 2026

Honestly, it's been a while (years) since I've done "complicated" git things like rebase and cherry pick because (being mostly solo) I adopted a far "straighter path" (hell, I could probably replace git with rcs for my typical workflow now-a-days, all that I'd need to do is make some shell script code to push and pull changes off my server). -e.g. I don't even branch anymore because I just CD to another directory, clone, code ideas and if they work I push otherwise I delete. ...I googled how I could cherry pick some of your PR in GitHub and it said I could not.

So, I pulled in your branch to my local repo and I was just thinking about cherry picking manually from my local. *shrug* Take for example the YAML file you made: that would be a simple, frictionless add but if I cherry pick, does that retain your authorship? I'm hesitating doing anything--even pushing updates I've done--because I don't really want to claim authorship of something you've done.

NOTE: I pulled the PR locally by something like: % git fetch origin pull/<ID>/head:<BRANCHNAME>

The simple stuff/adds aside (I'm sure those can be rebased without a problem), some of the refactoring you did I do have questions on. -e.g. the refactor of my hand rolled getopt() for flags. What was the purpose for that (if anything, getopt() should probably be adopted vs a custom one if possible).

Again, sorry, please forgive my lack of GitHub expertise but I really don't want to step on anyone's toes.

@msimerson
Copy link
Copy Markdown
Contributor Author

-e.g. the refactor of my hand rolled getopt() for flags. What was the purpose for that (if anything

Funny you mention getopt. I assumed you had a reason to hand roll the flags. All the changes were stuff that getopt does for you, such as option validation, bounds checking (assure args exist for -f and -d), warning on invalid options, starting at index 1 (0 is the program name), and centralizing the cleanup so memory was always deallocated.

getopt() should probably be adopted vs a custom one if possible

PR updated to use getopt

@JohnKaul
Copy link
Copy Markdown
Owner

JohnKaul commented May 6, 2026

lol ...no, don't add?! We need to remove before we can add. Besides I've added a new "feature" to handle indented key/value strings (like in the case of a jail.conf) and I've moved some code around a bit so I don't feel safe merging anything in sysconf.c or parse-config.c at the moment.

I hand rolled the option parser because it was/is/are dead simple options (it was faster and easier). Yes, I know what getopt() is.

Is it possible to split this up into smaller chunks and/or pick some areas to focus on instead of big reactors? I can start cherry picking some of the low hanging fruit or...whatever.

@JohnKaul
Copy link
Copy Markdown
Owner

JohnKaul commented May 6, 2026

FYI: I'm cleaning and pushing some changes now. I'm about to push the indented key/values change now. I'll stop adding/fixing so we can get this PR done.

@msimerson
Copy link
Copy Markdown
Contributor Author

msimerson commented May 6, 2026

You do you, I'm breaking this into smaller PRs for you. It's quite reasonable for a maintainer to want small discreet PRs that are easier to review and merge.

@msimerson msimerson closed this May 6, 2026
@JohnKaul
Copy link
Copy Markdown
Owner

JohnKaul commented May 6, 2026

latest fixes/updates pushed. I'm not worried about the getopt(), memory, or whatever stuff right now.

@msimerson
Copy link
Copy Markdown
Contributor Author

#11 is already open.

@JohnKaul
Copy link
Copy Markdown
Owner

JohnKaul commented May 6, 2026

you're fast.

BTW, I'm really not liking GitHub that much. So confusing sometimes.

@msimerson
Copy link
Copy Markdown
Contributor Author

GitHub, or git? Some decades ago, moving over to git was...a learning experience that lasted some 15 years or so and counting. It's a great tool, but it's got TOO many features, too many ways to do the same thing, and too many sharp edges. Wait, am I talking about git or GitHub again? 🤪

@JohnKaul
Copy link
Copy Markdown
Owner

JohnKaul commented May 6, 2026

git is *meh* these days for me. I have to refer to my helper file for most of the stuff that isn't "add", "commit", "log", "push" or "pull". :)

GitHub is crazy. I can't find anything and I'm afraid to click buttons.
My VCS server is headless (its all CLI based). Like this: https://github.com/JohnKaul/barevcs

@msimerson
Copy link
Copy Markdown
Contributor Author

Ask for help. :-) There's a LOT of us that have been here for longer than we'd like to admin. I'm off to the gym, I'll push a few more small tidy PRs when I get back.

@JohnKaul
Copy link
Copy Markdown
Owner

JohnKaul commented May 6, 2026

yeah, I'm off too. I have two kids to maintain.
l8r

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.

Exact key matching -e.g., 'keymap' vs 'keymaps'

3 participants