Repository navigation
cups-browsed: fix memory leaks when building cluster attributes - #88
Merged
tillkamppeter merged 1 commit intoNov 23, 2026
Merged
Conversation
check_printer_with_options() gets the supported values of two options for every cluster member via get_supported_options(), which returns a newly allocated array, but never frees either array. add_mediadatabase_attributes() allocates the media_type/media_source strings of its scratch entry for every media-col-database value and never frees them; the array keeps its own copies via copy_media(), but frees its entries with plain free(), leaking the strings inside them. Free both arrays in check_printer_with_options(), free the scratch strings after each value, and give the media database a free_media() callback that also frees the strings. These run whenever a cluster queue's attributes are (re)built, so a long-running cups-browsed with clustered printers grew without bound. Found with a libFuzzer/ASan harness for the cluster code path: on the same 512 inputs, LeakSanitizer reports 478592 bytes in 16311 allocations before this change and none after.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two leaks in the code that builds the merged attributes of a cluster queue. They run every time a cluster's attributes are (re)built, so a long-running cups-browsed with clustered printers keeps growing.
check_printer_with_options()callsget_supported_options()twice per cluster member. That returns a newly allocated array, and neither array was ever freed. This is most of the leak.add_mediadatabase_attributes()allocates themedia_type/media_sourcestrings of its scratch entry for everymedia-col-databasevalue and never frees them. The array keeps its own copies throughcopy_media(), but its free callback was plainfree(), so the strings inside each copy leaked too. This PR adds afree_media()callback and frees the scratch strings after each value.How I found it: with a libFuzzer + ASan harness for the cluster path (
get_cluster_attributes()→generate_cluster_conflicts()→get_cluster_sizes()→get_cluster_default_attributes()→ppdCreatePPDFromIPP2()), which I'm preparing for OpenPrinting/fuzzing#4. On the same 512 inputs, LeakSanitizer reports:Testing: builds without warnings against distro CUPS 2.4 (Ubuntu 24.04), and
make checkpasses (run as non-root with D-Bus and Avahi up, so the queues are created via DNS-SD and the test job completes).make checkdoesn't create a cluster, so the leak numbers above are what cover the changed code.The cppcheck job is red on master for unrelated reasons; #87 fixes that.