Remove incorrect defers that would free internal vips pointers#511
Merged
davidbyttow merged 4 commits intomasterfrom Mar 6, 2026
Merged
Remove incorrect defers that would free internal vips pointers#511davidbyttow merged 4 commits intomasterfrom
davidbyttow merged 4 commits intomasterfrom
Conversation
get_meta_loader wraps vips_image_get_string which returns an internal vips pointer that must not be freed by the caller. The defer was harmless (captured nil due to Go's defer evaluation semantics) but incorrect and misleading. Co-Authored-By: Claude Opus 4.6 <[email protected]>
get_image_delay wraps vips_image_get_array_int which returns an internal vips pointer that must not be freed by the caller. Co-Authored-By: Claude Opus 4.6 <[email protected]>
get_background wraps vips_image_get_array_double which returns an internal vips pointer that must not be freed by the caller. Co-Authored-By: Claude Opus 4.6 <[email protected]>
image_get_string wraps vips_image_get_string which returns an internal vips pointer that must not be freed by the caller. Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.
Summary
Four functions had
defercalls to free memory returned by vips getter functions that return internal pointers (not caller-owned allocations):vips_image_get_stringreturns internal pointer, must not freevips_image_get_array_intreturns internal pointer, must not freevips_image_get_array_doublereturns internal pointer, must not freevips_image_get_stringreturns internal pointer, must not freeThese defers were harmless in practice (Go's
defer f(x)evaluatesxat the defer statement, capturing nil before the C call populated the pointer), but they are incorrect and misleading. If someone "fixed" them with closures, they would corrupt vips internal data.Test plan
go build ./vips/go test ./vips/ -run "TestImage_Metadata|TestImage_Flip|TestImage_Crop|TestImage_Embed|TestImage_Resize"🤖 Generated with Claude Code
Note
Remove incorrect defers that free internal VIPS-owned pointers in
vips/operations.goDrop
deferfrees for VIPS-returned buffers and strings to avoid releasing internal memory in vips/operations.go.📍Where to Start
Start with the updated pointer ownership handling in
vipsImageGetMetaLoader,vipsImageGetDelay,vipsImageGetBackground, andvipsImageGetStringin vips/operations.go.Macroscope summarized f69fa90.