Skip to content

Commit 2a81014

Browse files
committed
Fixed memory and handle leaks in DirectShow frame grabbers
1 parent d9bb08d commit 2a81014

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

Source/Video/DirectshowFrameGrabber.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ class CSampleGrabberCB : public ISampleGrabberCB
8282
BufferEvent = nullptr;
8383
prev = 0;
8484
}
85+
86+
~CSampleGrabberCB() {
87+
if (BufferEvent) {
88+
CloseHandle(BufferEvent);
89+
}
90+
}
8591
std::mutex mutex_;
8692
DirectshowFrameGrabberPrivate *directShowPrivate;
8793
//CImgSavingThread* SavingThread;

Source/Video/DirectshowFrameGrabber2.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,18 @@ typedef struct tagVIDEOINFOHEADER2
143143

144144
class DirectshowFrameGrabber2Private: public CGrabCallback {
145145
public:
146+
class Initializer {
147+
public:
148+
Initializer() {
149+
}
150+
151+
~Initializer() {
152+
DbgTerminate();
153+
}
154+
};
155+
146156
DirectshowFrameGrabber2Private() {
157+
static Initializer initializer;
147158
memset(&vih, 0, sizeof(vih));
148159
}
149160

Source/Video/GrabFilter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CGrabFilter::CGrabFilter(LPUNKNOWN pUnk, CGrab* grab) :
3333
}
3434

3535
CGrabFilter::~CGrabFilter() {
36+
delete m_pPosition;
3637
}
3738

3839
CBasePin * CGrabFilter::GetPin(int n){
@@ -181,4 +182,4 @@ STDMETHODIMP CGrabInputPin::EndOfStream(void) {
181182
// Called when we are seeked
182183
STDMETHODIMP CGrabInputPin::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {
183184
return m_pDumpFilter->NewSegment(tStart, tStop, dRate);
184-
}
185+
}

Source/Video/GrabFilter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class CGrab
2828

2929
class CGrabFilter : public CBaseFilter
3030
{
31-
3231
CCritSec m_ReceiveLock;
3332
bool m_doGrab;
3433
CGrabCallback* m_callback;
@@ -81,4 +80,4 @@ class CGrabInputPin : public CRenderedInputPin
8180
STDMETHODIMP NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) override;
8281
};
8382

84-
#endif
83+
#endif

0 commit comments

Comments
 (0)