diff options
author | He Junyan <junyan.he@intel.com> | 2021-09-19 17:39:09 +0300 |
---|---|---|
committer | He Junyan <junyan.he@intel.com> | 2021-09-19 17:43:06 +0300 |
commit | 25dbae6e735ad68bf30780cbd1d917e7c5f0629d (patch) | |
tree | a74a4674b5d047f7fe9aa409912f5ac88cdc1df3 | |
parent | 81cf9754e3c29148fd7a867241a87e2ac72e398b (diff) |
bitwriter: Fix a memory leak in reset_and_get_buffer.
We should record the ownership of the data before we reset the bitwriter.
Or we will always dup the buffer data and leak the memory.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/886>
-rw-r--r-- | libs/gst/base/gstbitwriter.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/libs/gst/base/gstbitwriter.c b/libs/gst/base/gstbitwriter.c index 887480a76c..7086c3c3d6 100644 --- a/libs/gst/base/gstbitwriter.c +++ b/libs/gst/base/gstbitwriter.c @@ -225,15 +225,18 @@ gst_bit_writer_reset_and_get_buffer (GstBitWriter * bitwriter) GstBuffer *buffer; gpointer data; gsize size; + gboolean owned; g_return_val_if_fail (bitwriter != NULL, NULL); + owned = bitwriter->owned; + size = GST_ROUND_UP_8 (bitwriter->bit_size) >> 3; data = gst_bit_writer_reset_and_get_data (bitwriter); /* we cannot rely on buffers allocated externally, thus let's dup * the data */ - if (data && !bitwriter->owned) + if (data && !owned) data = g_memdup2 (data, size); buffer = gst_buffer_new (); |