Skip to content

Fix static analysis warnings and memory leaks (cppcheck)#133

Merged
tillkamppeter merged 18 commits intoOpenPrinting:masterfrom
rkt0209:c-bug-fixes
Mar 6, 2026
Merged

Fix static analysis warnings and memory leaks (cppcheck)#133
tillkamppeter merged 18 commits intoOpenPrinting:masterfrom
rkt0209:c-bug-fixes

Conversation

@rkt0209
Copy link
Copy Markdown
Contributor

@rkt0209 rkt0209 commented Mar 6, 2026

This PR resolves a series of warnings and errors caught by cppcheck static analysis across the codebase.

Key fixes include:

  • Memory Leaks: Fixed realloc memory leak patterns (nulled but not freed upon failure) in catalog.c, filter.c, pwgtopdf.c, and testfilters.c. Added missing pdfioFileClose() in pclmtoraster.c and freed leaked structs in bannertopdf.c.
  • Null Pointer Dereferences: Added safety guards and corrected order of operations to prevent cross-translation unit (CTU) null pointer dereferences in image.c, libcups2.c, and pdftopdf.c.
  • Uninitialized Variables: Handled uninitialized pdfio_matrix_t variables in pdftopdf.c by explicitly defining them as identity matrices.
  • Format Specifiers: Fixed [invalidPrintfArgType_sint] warnings by changing %d to %u where unsigned int variables were being passed in ghostscript.c, pwgtopdf.c, and test-analyze.c.
  • False Positives: Added cppcheck-suppress comments for known macro-expansion false positives in sfnt.c and test-analyze.c to keep CI logs clean.

All changes have been tested locally and successfully compile.

@tillkamppeter tillkamppeter merged commit b558b36 into OpenPrinting:master Mar 6, 2026
1 check passed
tillkamppeter pushed a commit that referenced this pull request Mar 18, 2026
…estfilters.c (#137)

This specific block of code was correctly removed in PR #122. It was inadvertently re-introduced during a Git merge conflict resolution in PR #133 while I was applying memory safety fixes. This PR cleans up that accidental inclusion and restores the file to its intended state.
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