Rémi Bernon : winegstreamer: Move the conditional cleanup to the create error path.

Alexandre Julliard julliard at winehq.org
Tue Feb 22 16:06:52 CST 2022


Module: wine
Branch: master
Commit: 34a55c7b96c97b178ea1ab519eb0e847096f2076
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=34a55c7b96c97b178ea1ab519eb0e847096f2076

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Tue Feb 22 12:23:22 2022 -0600

winegstreamer: Move the conditional cleanup to the create error path.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51931
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52391
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winegstreamer/wg_transform.c | 73 +++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 42 deletions(-)

diff --git a/dlls/winegstreamer/wg_transform.c b/dlls/winegstreamer/wg_transform.c
index e4545774428..c309523dd36 100644
--- a/dlls/winegstreamer/wg_transform.c
+++ b/dlls/winegstreamer/wg_transform.c
@@ -62,12 +62,10 @@ NTSTATUS wg_transform_destroy(void *args)
 {
     struct wg_transform *transform = args;
 
-    if (transform->my_sink)
-        g_object_unref(transform->my_sink);
-    if (transform->my_src)
-        g_object_unref(transform->my_src);
-
+    g_object_unref(transform->my_sink);
+    g_object_unref(transform->my_src);
     free(transform);
+
     return STATUS_SUCCESS;
 }
 
@@ -77,61 +75,52 @@ NTSTATUS wg_transform_create(void *args)
     struct wg_format output_format = *params->output_format;
     struct wg_format input_format = *params->input_format;
     GstCaps *src_caps = NULL, *sink_caps = NULL;
+    NTSTATUS status = STATUS_UNSUCCESSFUL;
     GstPadTemplate *template = NULL;
     struct wg_transform *transform;
-    NTSTATUS status;
 
     if (!init_gstreamer())
         return STATUS_UNSUCCESSFUL;
 
-    status = STATUS_NO_MEMORY;
-
     if (!(transform = calloc(1, sizeof(*transform))))
-        goto done;
+        return STATUS_NO_MEMORY;
 
     if (!(src_caps = wg_format_to_caps(&input_format)))
-        goto done;
-    if (!(sink_caps = wg_format_to_caps(&output_format)))
-        goto done;
-
+        goto out_free_transform;
     if (!(template = gst_pad_template_new("src", GST_PAD_SRC, GST_PAD_ALWAYS, src_caps)))
-        goto done;
-    if (!(transform->my_src = gst_pad_new_from_template(template, "src")))
-        goto done;
+        goto out_free_src_caps;
+    transform->my_src = gst_pad_new_from_template(template, "src");
     g_object_unref(template);
-    template = NULL;
+    if (!transform->my_src)
+        goto out_free_src_caps;
 
+    if (!(sink_caps = wg_format_to_caps(&output_format)))
+        goto out_free_src_pad;
     if (!(template = gst_pad_template_new("sink", GST_PAD_SINK, GST_PAD_ALWAYS, sink_caps)))
-        goto done;
-    if (!(transform->my_sink = gst_pad_new_from_template(template, "sink")))
-        goto done;
+        goto out_free_sink_caps;
+    transform->my_sink = gst_pad_new_from_template(template, "sink");
     g_object_unref(template);
-    template = NULL;
+    if (!transform->my_sink)
+        goto out_free_sink_caps;
 
     gst_pad_set_element_private(transform->my_sink, transform);
     gst_pad_set_chain_function(transform->my_sink, transform_sink_chain_cb);
 
-    status = STATUS_SUCCESS;
-
-done:
-    if (template)
-        g_object_unref(template);
-    if (sink_caps)
-        gst_caps_unref(sink_caps);
-    if (src_caps)
-        gst_caps_unref(src_caps);
-
-    if (status)
-    {
-        GST_ERROR("Failed to create winegstreamer transform.");
-        if (transform)
-            wg_transform_destroy(transform);
-    }
-    else
-    {
-        GST_INFO("Created winegstreamer transform %p.", transform);
-        params->transform = transform;
-    }
+    gst_caps_unref(sink_caps);
+    gst_caps_unref(src_caps);
+
+    GST_INFO("Created winegstreamer transform %p.", transform);
+    params->transform = transform;
+    return STATUS_SUCCESS;
 
+out_free_sink_caps:
+    gst_caps_unref(sink_caps);
+out_free_src_pad:
+    gst_object_unref(transform->my_src);
+out_free_src_caps:
+    gst_caps_unref(src_caps);
+out_free_transform:
+    free(transform);
+    GST_ERROR("Failed to create winegstreamer transform.");
     return status;
 }




More information about the wine-cvs mailing list