From 5ffd2c64a0cca7b55e280d61d225e45858bc4aa0 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Thu, 13 Aug 2020 02:24:52 +0900 Subject: [PATCH] mediafoundation: Call MFShutdown when destroying plugin MFStartup and MFShutdown should be paired as documented in https://docs.microsoft.com/en-us/windows/win32/api/mfapi/nf-mfapi-mfstartup#remarks Otherwise valgrind-like tools would report false positive memory leak. Part-of: --- sys/mediafoundation/plugin.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sys/mediafoundation/plugin.c b/sys/mediafoundation/plugin.c index 509b15fade..923f5b03ed 100644 --- a/sys/mediafoundation/plugin.c +++ b/sys/mediafoundation/plugin.c @@ -43,6 +43,12 @@ GST_DEBUG_CATEGORY (gst_mf_transform_debug); #define GST_CAT_DEFAULT gst_mf_debug +static void +plugin_deinit (gpointer data) +{ + MFShutdown (); +} + static gboolean plugin_init (GstPlugin * plugin) { @@ -85,6 +91,17 @@ plugin_init (GstPlugin * plugin) gst_mf_aac_enc_plugin_init (plugin, GST_RANK_SECONDARY); gst_mf_mp3_enc_plugin_init (plugin, GST_RANK_SECONDARY); + /* So that call MFShutdown() when this plugin is no more used + * (i.e., gst_deinit). Otherwise valgrind-like tools would complain + * about un-released media foundation resources. + * + * NOTE: MFStartup and MFShutdown can be called multiple times, but the number + * of each MFStartup and MFShutdown call should be identical. This rule is + * simliar to that of CoInitialize/CoUninitialize pair */ + g_object_set_data_full (G_OBJECT (plugin), + "plugin-mediafoundation-shutdown", "shutdown-data", + (GDestroyNotify) plugin_deinit); + return TRUE; }