[vlc-devel] [PATCH] d3d11va: fix leak from a FromWide() call

Steve Lhomme robux4 at videolabs.io
Wed Mar 15 09:12:02 CET 2017


---
 modules/codec/avcodec/d3d11va.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index f6f2dbc49b..8fc59d40ba 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -652,6 +652,7 @@ static char *DxDescribe(directx_sys_t *dx_sys)
        return NULL;
     }
 
+    char *description = NULL;
     DXGI_ADAPTER_DESC adapterDesc;
     if (SUCCEEDED(IDXGIAdapter_GetDesc(p_adapter, &adapterDesc))) {
         const char *vendor = "Unknown";
@@ -662,17 +663,19 @@ static char *DxDescribe(directx_sys_t *dx_sys)
             }
         }
 
-        char *description;
-        if (asprintf(&description, "D3D11VA (%s, vendor %u(%s), device %u, revision %u)",
-                     FromWide(adapterDesc.Description),
-                     adapterDesc.VendorId, vendor, adapterDesc.DeviceId, adapterDesc.Revision) < 0)
-            return NULL;
-        IDXGIAdapter_Release(p_adapter);
-        return description;
+        char *utfdesc = FromWide(adapterDesc.Description);
+        if (likely(utfdesc!=NULL))
+        {
+            if (asprintf(&description, "D3D11VA (%s, vendor %u(%s), device %u, revision %u)",
+                         utfdesc,
+                         adapterDesc.VendorId, vendor, adapterDesc.DeviceId, adapterDesc.Revision) < 0)
+                description = NULL;
+            free(utfdesc);
+        }
     }
 
     IDXGIAdapter_Release(p_adapter);
-    return NULL;
+    return description;
 }
 
 /**
-- 
2.11.1



More information about the vlc-devel mailing list