From: He Junyan Date: Sun, 19 Sep 2021 14:39:09 +0000 (+0800) Subject: bitwriter: Fix a memory leak in reset_and_get_buffer. X-Git-Tag: 1.19.3~517 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=25dbae6e735ad68bf30780cbd1d917e7c5f0629d;p=platform%2Fupstream%2Fgstreamer.git 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: --- diff --git a/libs/gst/base/gstbitwriter.c b/libs/gst/base/gstbitwriter.c index 887480a..7086c3c 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 ();