Skip to content

Commit f022a61

Browse files
authored
Fix memory leak in decode_webp (#8712)
1 parent 868a3b4 commit f022a61

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

torchvision/csrc/io/image/cpu/decode_webp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ torch::Tensor decode_webp(
4444

4545
auto decoded_data =
4646
decoding_func(encoded_data_p, encoded_data_size, &width, &height);
47+
4748
TORCH_CHECK(decoded_data != nullptr, "WebPDecodeRGB[A] failed.");
4849

50+
auto deleter = [decoded_data](void*) { WebPFree(decoded_data); };
4951
auto out = torch::from_blob(
50-
decoded_data, {height, width, num_channels}, torch::kUInt8);
52+
decoded_data, {height, width, num_channels}, deleter, torch::kUInt8);
5153

5254
return out.permute({2, 0, 1});
5355
}

0 commit comments

Comments
 (0)