Skip to content

Commit 4adbd54

Browse files
committed
Fix duplicated memory allocation in StreamWriter (#2906)
Summary: Pull Request resolved: #2906 The correct way to create AVFormatContext* for output is to pass an address of an uninitialized *AVFormatContext struct to `avformat_alloc_output_context2` function. The current code pre-allocates AVFormatContext* with `avformat_alloc_context`, then this allocated object is lost inside of `avformat_alloc_output_context2`. Reviewed By: xiaohui-zhang Differential Revision: D41865685 fbshipit-source-id: 9a9dc83b5acfe9b450f191fe716c85ebb5a5d842
1 parent 30a1070 commit 4adbd54

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

torchaudio/csrc/ffmpeg/stream_writer/stream_writer_wrapper.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ AVFormatOutputContextPtr get_output_format_context(
1313
"`format` must be provided when the input is file-like object.");
1414
}
1515

16-
AVFormatContext* p = avformat_alloc_context();
17-
TORCH_CHECK(p, "Failed to allocate AVFormatContext.");
18-
16+
AVFormatContext* p = nullptr;
1917
int ret = avformat_alloc_output_context2(
2018
&p, nullptr, format ? format.value().c_str() : nullptr, dst.c_str());
2119
TORCH_CHECK(

0 commit comments

Comments
 (0)