From f441515357e80620308f9c2db573db81cffa7a64 Mon Sep 17 00:00:00 2001 From: corley Date: Tue, 27 Mar 2018 00:54:48 +0300 Subject: [PATCH] Fixed a couple of memory leaks in videoInput::getDevice() when multiple devices are present in the system --- modules/videoio/src/cap_dshow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/videoio/src/cap_dshow.cpp b/modules/videoio/src/cap_dshow.cpp index 9ea554fa21..42af3a3948 100644 --- a/modules/videoio/src/cap_dshow.cpp +++ b/modules/videoio/src/cap_dshow.cpp @@ -2912,7 +2912,7 @@ HRESULT videoInput::getDevice(IBaseFilter** gottaFilter, int deviceId, WCHAR * w // Enumerate the monikers. IMoniker *pMoniker = NULL; ULONG cFetched; - while ((pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) && (!done)) + while ((!done) && (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)) { if(deviceCounter == deviceId) { @@ -2951,6 +2951,12 @@ HRESULT videoInput::getDevice(IBaseFilter** gottaFilter, int deviceId, WCHAR * w pMoniker = NULL; } } + else + { + // cleaning for the case when this isn't the device we are looking for + pMoniker->Release(); + pMoniker = NULL; + } deviceCounter++; } pEnumCat->Release();