Description
vipsExifStringTag and vipsExifIntTag in vips.go allocate a C string with C.CString(tag) but never free it, so every call leaks it on the C heap.
|
func vipsExifStringTag(image *C.VipsImage, tag string) string { |
|
return vipsExifShort(C.GoString(C.vips_exif_tag(image, C.CString(tag)))) |
|
} |
|
|
|
func vipsExifIntTag(image *C.VipsImage, tag string) int { |
|
return int(C.vips_exif_tag_to_int(image, C.CString(tag))) |
Impact
Metadata() reads ~50 EXIF fields through these two helpers, and Size() / Image.Metadata() go through Metadata() as well. So anything that reads image metadata per request leaks ~50 small allocations per image. Over time the C heap keeps growing — RSS climbs while the Go heap stays flat — until the process becomes unresponsive.
Suggested fix
Free it, the same way the other C.CString call sites already do (vipsWindowSize, vipsWatermark, vipsTransformICC):
func vipsExifStringTag(image *C.VipsImage, tag string) string {
cTag := C.CString(tag)
defer C.free(unsafe.Pointer(cTag))
return vipsExifShort(C.GoString(C.vips_exif_tag(image, cTag)))
}
func vipsExifIntTag(image *C.VipsImage, tag string) int {
cTag := C.CString(tag)
defer C.free(unsafe.Pointer(cTag))
return int(C.vips_exif_tag_to_int(image, cTag))
}
Still present on master (a14e08d). Happy to send a PR.
Related
Possibly related: #440, #282.
Description
vipsExifStringTagandvipsExifIntTaginvips.goallocate a C string withC.CString(tag)but never free it, so every call leaks it on the C heap.bimg/vips.go
Lines 245 to 250 in a14e08d
Impact
Metadata()reads ~50 EXIF fields through these two helpers, andSize()/Image.Metadata()go throughMetadata()as well. So anything that reads image metadata per request leaks ~50 small allocations per image. Over time the C heap keeps growing — RSS climbs while the Go heap stays flat — until the process becomes unresponsive.Suggested fix
Free it, the same way the other
C.CStringcall sites already do (vipsWindowSize,vipsWatermark,vipsTransformICC):Still present on master (
a14e08d). Happy to send a PR.Related
Possibly related: #440, #282.