Skip to content

Commit

Permalink
Merge pull request #72 from Photoroom/ben/deep_copy_prior_to_release
Browse files Browse the repository at this point in the history
[hotfix] Race condition on the buffer release
  • Loading branch information
tarek-ayed authored Jan 22, 2025
2 parents 54e42ce + 4002504 commit 5cc2833
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/serdes.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,15 @@ func imageFromBuffer(buffer []byte, transform *ARAwareTransform, aspectRatio flo
panic("Bit depth not set")
}

// Do a deep copy of the image bytes, so we can release the vips image
data := make([]byte, len(imgBytes))
copy(data, imgBytes)

// Release the vips image, will free underlying buffers without having to resort to the GC
img.Close()

imgPayload := ImagePayload{
Data: imgBytes,
Data: data,
OriginalHeight: originalHeight,
OriginalWidth: originalWidth,
Height: height,
Expand Down

0 comments on commit 5cc2833

Please sign in to comment.