From 025b3de29c63e5a05f66bd5354d7e90c2ccad417 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Thu, 24 Sep 2020 22:22:55 -0500 Subject: [PATCH] winegstreamer: Avoid leaking a newly allocated buffer on failure in request_buffer_src(). According to the GStreamer documentation, the contents of "buffer" should be considered undefined on failure, which means that the caller has no way of freeing a newly allocated buffer. Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- dlls/winegstreamer/gstdemux.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/dlls/winegstreamer/gstdemux.c b/dlls/winegstreamer/gstdemux.c index 9a9fe01936b..acb15dc9238 100644 --- a/dlls/winegstreamer/gstdemux.c +++ b/dlls/winegstreamer/gstdemux.c @@ -878,13 +878,14 @@ static GstFlowReturn got_data_sink(GstPad *pad, GstObject *parent, GstBuffer *bu return GST_FLOW_OK; } -static GstFlowReturn request_buffer_src(GstPad *pad, GstObject *parent, guint64 ofs, guint len, GstBuffer **buf) +static GstFlowReturn request_buffer_src(GstPad *pad, GstObject *parent, guint64 ofs, guint len, GstBuffer **buffer) { struct gstdemux *This = gst_pad_get_element_private(pad); + GstBuffer *new_buffer = NULL; HRESULT hr; GstMapInfo info; - TRACE("pad %p, offset %s, length %u, buffer %p.\n", pad, wine_dbgstr_longlong(ofs), len, *buf); + TRACE("pad %p, offset %s, length %u, buffer %p.\n", pad, wine_dbgstr_longlong(ofs), len, *buffer); if (ofs == GST_BUFFER_OFFSET_NONE) ofs = This->nextpullofs; @@ -896,13 +897,16 @@ static GstFlowReturn request_buffer_src(GstPad *pad, GstObject *parent, guint64 len = This->filesize - ofs; This->nextpullofs = ofs + len; - if (!*buf) - *buf = gst_buffer_new_and_alloc(len); - gst_buffer_map(*buf, &info, GST_MAP_WRITE); + if (!*buffer) + *buffer = new_buffer = gst_buffer_new_and_alloc(len); + gst_buffer_map(*buffer, &info, GST_MAP_WRITE); hr = IAsyncReader_SyncRead(This->reader, ofs, len, info.data); - gst_buffer_unmap(*buf, &info); - if (FAILED(hr)) { - ERR("Returned %08x\n", hr); + gst_buffer_unmap(*buffer, &info); + if (FAILED(hr)) + { + ERR("Failed to read data, hr %#x.\n", hr); + if (new_buffer) + gst_buffer_unref(new_buffer); return GST_FLOW_ERROR; }