Skip to content

Fix: leak of -PCC profiles in iccApplyToLink on error exit paths (#1336)#1339

Merged
xsscx merged 1 commit into
InternationalColorConsortium:masterfrom
colourbill-ctrl:fix-1336-applytolink-pcc-leak
Jun 14, 2026
Merged

Fix: leak of -PCC profiles in iccApplyToLink on error exit paths (#1336)#1339
xsscx merged 1 commit into
InternationalColorConsortium:masterfrom
colourbill-ctrl:fix-1336-applytolink-pcc-leak

Conversation

@colourbill-ctrl

Copy link
Copy Markdown
Contributor

Summary

Fixes #1336iccApplyToLink leaks its -PCC profiles when the chain fails to assemble.

The tool opens each -PCC profile and tracks it in pccList, releasing the list only after cmm.Begin() consumes the connection conditions. Three error-exit paths before that point returned without freeing pccList:

  • -PCC open failure (leaks earlier-iteration entries)
  • AddXform failure — e.g. icCmmStatBadSpaceLink when a profile doesn't connect to the chain (the path the issue's repro hits)
  • Begin() failure

Reproduction (issue's exact command, under ASan/LSan)

iccApplyToLink Results/qa_link_pcc.icc 0 17 1 QA_Link_PCC 0.0 1.0 0 1 \
  ICC/Spec380_10_730-D50_2deg.icc 3 -PCC ICC/Spec400_10_700-IllumA_2deg-Abs.icc \
  ../sRGB_v4_ICC_preference.icc 1

The sRGB profile doesn't connect to the spectral chain → AddXform returns BadSpaceLink → early return -1 strands the -PCC Spec400 profile:

Indirect leak of ... CIccProfile::ReadBasic(CIccIO*) IccProfile.cpp:1363
  ... OpenIccProfile -> main iccApplyToLink.cpp  (the -PCC open)
SUMMARY: AddressSanitizer: 608 byte(s) leaked

(The tool's error message looked "silent" only because LeakSanitizer's _exit discards the buffered stdout; with leak detection off it prints Error - Unable to add '…' (status 2: Invalid space link).)

Fix

Centralize the release in a releasePccList() helper and call it on every exit path. The main (non--PCC) profiles are unaffected — AddXform owns and frees them on failure (#1327).

Verification

  • The repro is now LSan-clean and prints its real error (tool exit 255, no leak summary).
  • No regression: valid links with and without -PCC still succeed (LUT written) and stay ASan/LSan-clean — the success-path cleanup is the same delete loop, just factored into the helper.

Related: #1337 (the CIccCmm::CheckPCSConnections CIccPcsXform leak, PR #1338) is a different path reached only once Begin() runs; this iccApplyToLink command fails earlier at AddXform, so the two leaks are independent.

🤖 Generated with Claude Code

…ernationalColorConsortium#1336)

iccApplyToLink opens each -PCC profile and tracks it in pccList, freeing the
list only after cmm.Begin() has consumed the connection conditions. The three
error-exit paths before that point returned without freeing pccList:
  - -PCC open failure (frees earlier-iteration entries)
  - AddXform failure (e.g. icCmmStatBadSpaceLink when a profile does not connect
    to the chain) -- the path the issue's repro hits
  - Begin() failure
so the accumulated -PCC profiles leaked.

Surfaced by the iccApplyToLink CI repro under ASan (InternationalColorConsortium#1336): an indirect leak of
the -PCC profile via CIccProfile::ReadBasic (IccProfile.cpp:1363) opened at
iccApplyToLink.cpp; the tool's stdout error was simply lost to LeakSanitizer's
exit, which is why the run looked silent.

Centralize the release in releasePccList() and call it on every exit path. The
main (non-PCC) profiles are unaffected: AddXform owns and frees them on failure
(InternationalColorConsortium#1327). Verified: the repro is now LSan-clean and prints its real error; valid
links with and without -PCC still succeed and stay clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added Tools Command-line tool or GUI tool changes Source C or C++ source code changes labels Jun 14, 2026

@xsscx xsscx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2026-06-14 03:16:58 UTC

@colourbill-ctrl

Copy link
Copy Markdown
Contributor Author

Maintainer note — paired with #1340 (the ASan regression). #1340 is on an upstream branch because the fork-PR automation gate blocks fork PRs from .github/Build/Cmake.

Suggested merge order: #1339 (this fix) first, then #1340. #1340 is red until this fix is on master — by design, since it reproduces the leak it guards.

@xsscx xsscx added the Merge Ready Approved, mergeable, and all CI checks passed label Jun 14, 2026
@xsscx

xsscx commented Jun 14, 2026

Copy link
Copy Markdown
Member

Note: Auto-Merge is On. Merge on your Schedule.

@xsscx xsscx merged commit 9b65b40 into InternationalColorConsortium:master Jun 14, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merge Ready Approved, mergeable, and all CI checks passed Source C or C++ source code changes Tools Command-line tool or GUI tool changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI c0d0fc2: Indirect Leak in CIccProfile::ReadBasic() at IccProfile.cpp:1363

2 participants