Repository navigation
foomatic-rip: free the previous value before overwriting it in composite_set_values - #822
Merged
tillkamppeter merged 1 commit intoNov 28, 2026
Conversation
…ite_set_values
All three branches of composite_set_values() do:
val = option_assure_value(dep, optionset);
val->fromoption = opt;
val->value = get_valid_value_string(dep, ...);
option_assure_value() returns the *existing* value_t for (dep,
optionset) if one is already there, not a fresh one -- it only
allocates when none exists yet (option_find_value() returns NULL).
Once a composite option has set a dependent option's value for a
given optionset once, every later call that sets it again for the
same optionset overwrites val->value with a new
get_valid_value_string() string without freeing the one already
there, leaking it.
option_set_value(), right above this function, sets a value_t's
->value field for the same reason and does free(val->value) first --
this is the same pattern, just missing it in all three places here.
Added the missing free(val->value) before each assignment; it's a
correctly-sized no-op the first time a value_t is populated, since
option_assure_value() calloc()s new ones (value starts NULL).
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.
All three branches of
composite_set_values()do:option_assure_value()returns the existingvalue_tfor(dep, optionset)if one is already there, not a fresh one — it only allocates when none exists yet (option_find_value()returns NULL). Once a composite option has set a dependent option's value for a given optionset once, every later call that sets it again for the same optionset overwritesval->valuewith a newget_valid_value_string()string without freeing the one already there, leaking it.option_set_value(), right above this function, sets avalue_t's->valuefield for the same reason and doesfree(val->value)first — this is the same pattern, just missing it in all three places here.Added the missing
free(val->value)before each assignment; it's a correctly-sized no-op the first time avalue_tis populated, sinceoption_assure_value()calloc()s new ones (valuestarts NULL).Verified by building this branch against current upstream
libcupsfiltersandlibppd,make/make checkclean.