Skip to content

Commit eedca60

Browse files
NicolasHugatalman
andauthored
Reapply "Fix memory leak in decode_webp (#8712)" (#8723) (#8724)
Co-authored-by: atalman <atalman@fb.com>
1 parent cd839f1 commit eedca60

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

packaging/pre_build_script.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ else
3232
conda install -yq ffmpeg=4.2 libjpeg-turbo -c pytorch-nightly
3333
fi
3434

35-
yum install -y libjpeg-turbo-devel libwebp-devel freetype gnutls
35+
conda install libwebp -yq
36+
conda install libjpeg-turbo -c pytorch
37+
yum install -y freetype gnutls
3638
pip install auditwheel
3739
fi
3840

test/test_image.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
IS_MACOS = sys.platform == "darwin"
4646
PILLOW_VERSION = tuple(int(x) for x in PILLOW_VERSION.split("."))
4747
WEBP_TEST_IMAGES_DIR = os.environ.get("WEBP_TEST_IMAGES_DIR", "")
48+
# See https://github.com/pytorch/vision/pull/8724#issuecomment-2503964558
49+
ROCM_WEBP_MESSAGE = "ROCM not built with webp support."
4850

4951
# Hacky way of figuring out whether we compiled with libavif/libheif (those are
5052
# currenlty disabled by default)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#if WEBP_FOUND
55
#include "webp/decode.h"
6+
#include "webp/types.h"
67
#endif // WEBP_FOUND
78

89
namespace vision {
@@ -44,10 +45,12 @@ torch::Tensor decode_webp(
4445

4546
auto decoded_data =
4647
decoding_func(encoded_data_p, encoded_data_size, &width, &height);
48+
4749
TORCH_CHECK(decoded_data != nullptr, "WebPDecodeRGB[A] failed.");
4850

51+
auto deleter = [decoded_data](void*) { WebPFree(decoded_data); };
4952
auto out = torch::from_blob(
50-
decoded_data, {height, width, num_channels}, torch::kUInt8);
53+
decoded_data, {height, width, num_channels}, deleter, torch::kUInt8);
5154

5255
return out.permute({2, 0, 1});
5356
}

0 commit comments

Comments
 (0)