Skip to content

cups-browsed: fix cppcheck 2.19 findings - #87

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
rue19:fix-cppcheck-2.19
Nov 23, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
rue19:fix-cppcheck-2.19

Conversation

@rue19

@rue19 rue19 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

The cppcheck job has been failing on master since 2026-11-18. No code change caused it: ubuntu-latest moved to Ubuntu 26.04, which installs cppcheck 2.19 instead of 2.13 (compare the "Setting up cppcheck" line in the runs for 2869a8b and 4aa6023). The newer version reports 20 findings on master.

  • nullPointerRedundantCheck (type/domain) in create_remote_printer_entry() and examine_discovered_printer_record(). Both functions already return early when type or domain is NULL, so the later != NULL checks are redundant. Removed them, which leaves the [0] != '\0' checks.
  • nullPointerOutOfMemory: unchecked malloc()/calloc()/strdup() in update_cups_queues(), get_cluster_default_attributes(), remove_bad_chars() and read_browseallow_value(). Each now bails out the way the surrounding code handles other errors. In update_cups_queues() the queue simply stays STATUS_TO_BE_CREATED and is retried on the next pass.
  • memleak: when no queue-creation thread can be started after all retries, the create_args_t was freed but its queue and uri strings were not. That's a real (small) leak, and this PR fixes it.

I didn't pin the runner back to 24.04, because that would only hide the findings.

Testing: in an ubuntu:26.04 container with the exact cppcheck command from .github/workflows/cppcheck.yml, master exits 1 with 20 findings and this branch exits 0 with none. The build succeeds and make check passes (non-root, D-Bus + Avahi up).

The cppcheck job has been failing since ubuntu-latest moved to Ubuntu
26.04, which ships cppcheck 2.19 instead of 2.13. It reports 20
findings on master:

- nullPointerRedundantCheck for type/domain in
  create_remote_printer_entry() and examine_discovered_printer_record().
  Both functions already return early when type or domain is NULL, so
  the later "!= NULL" checks are redundant; remove them.

- nullPointerOutOfMemory for unchecked malloc()/calloc()/strdup()
  results in update_cups_queues(), get_cluster_default_attributes(),
  remove_bad_chars() and read_browseallow_value(). Check them and
  bail out the same way the surrounding code handles other errors.

- memleak: when no queue-creation thread can be started after all
  retries, the create_args_t was freed but its queue and uri strings
  were not. Free them too.

With this, cppcheck 2.19 (same options as the CI job) reports nothing.
The build and "make check" still pass.
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