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
PPD parser: Only last "Emulators" statement is taken into account + memory leak #5475
Conversation
…emory leak Each occurence of "Emulators" keyword overwrites the previous parsed "Emulators" statement. It also causes a memory leak. The problem is solved here by concatenating together values from all occurences of "Emulators" statements.
Happy to fix this, but keep in mind that CUPS never uses the value and PPDs are long deprecated... |
@@ -654,6 +655,7 @@ _ppdOpen( | |||
ppd->landscape = -90; | |||
ppd->coptions = cupsArrayNew((cups_array_func_t)ppd_compare_coptions, | |||
NULL); | |||
ppd->emulations = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary because ppd_file_t structure is zeroed.
@@ -1202,27 +1204,32 @@ _ppdOpen( | |||
sptr ++; | |||
} | |||
|
|||
ppd->num_emulations = count; | |||
if ((ppd->emulations = calloc((size_t)count, sizeof(ppd_emul_t))) == NULL) | |||
temp_ptr = realloc(ppd->emulations, (size_t)(ppd->num_emulations+count)*sizeof(ppd_emul_t)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, CUPS runs on platforms where realloc(NULL, size)
will crash hard. But I can refactor this.
This also eliminates a potential memory leak...
This also addresses a potential memory leak...
I opted to just remove the code that deals with the emulations array completely - nothing in CUPS uses this array and it was just more "dead code" cluttering up libcups. [master 4b5a691] Stop parsing the Emulators keywords in PPD files (Issue #5475) [branch-2.2 558bba7] Stop parsing the Emulators keywords in PPD files (Issue #5475) |
Each occurence of "Emulators" keyword overwrites the previous parsed
"Emulators" statement. It also causes a memory leak. The problem is solved here
by concatenating together values from all occurences of "Emulators" statements.