diff --git a/src/media/video/winvideo/video_device_monitor_impl.cpp b/src/media/video/winvideo/video_device_monitor_impl.cpp
index e66624e29bf70f90afeac4f8a857812bc8f5d78b..330c565432111f2beeaffa70544ad1eab8107b22 100644
--- a/src/media/video/winvideo/video_device_monitor_impl.cpp
+++ b/src/media/video/winvideo/video_device_monitor_impl.cpp
@@ -105,17 +105,17 @@ VideoDeviceMonitorImpl::run()
     hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
         CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDevEnum));
 
-    IEnumMoniker *pEnum;
+    IEnumMoniker *pEnum = nullptr;
     if (SUCCEEDED(hr)) {
         hr = pDevEnum->CreateClassEnumerator(
             CLSID_VideoInputDeviceCategory,
             &pEnum, 0);
-        if (FAILED(hr)) {
+        pDevEnum->Release();
+        if (FAILED(hr) || pEnum == nullptr) {
             RING_ERR("No webcam found.");
             hr = VFW_E_NOT_FOUND;
         }
-        pDevEnum->Release();
-        if (hr != VFW_E_NOT_FOUND) {
+        if (hr != VFW_E_NOT_FOUND && pEnum != nullptr) {
             IMoniker *pMoniker = NULL;
             unsigned deviceID = 0;
             while (pEnum->Next(1, &pMoniker, NULL) == S_OK)