Skip to content

Commit

Permalink
Fixed memory and handle leaks in DirectShow frame grabbers
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Nov 4, 2024
1 parent d9bb08d commit 2a81014
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Source/Video/DirectshowFrameGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class CSampleGrabberCB : public ISampleGrabberCB
BufferEvent = nullptr;
prev = 0;
}

~CSampleGrabberCB() {
if (BufferEvent) {
CloseHandle(BufferEvent);
}
}
std::mutex mutex_;
DirectshowFrameGrabberPrivate *directShowPrivate;
//CImgSavingThread* SavingThread;
Expand Down
11 changes: 11 additions & 0 deletions Source/Video/DirectshowFrameGrabber2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ typedef struct tagVIDEOINFOHEADER2

class DirectshowFrameGrabber2Private: public CGrabCallback {
public:
class Initializer {
public:
Initializer() {
}

~Initializer() {
DbgTerminate();
}
};

DirectshowFrameGrabber2Private() {
static Initializer initializer;
memset(&vih, 0, sizeof(vih));
}

Expand Down
3 changes: 2 additions & 1 deletion Source/Video/GrabFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CGrabFilter::CGrabFilter(LPUNKNOWN pUnk, CGrab* grab) :
}

CGrabFilter::~CGrabFilter() {
delete m_pPosition;
}

CBasePin * CGrabFilter::GetPin(int n){
Expand Down Expand Up @@ -181,4 +182,4 @@ STDMETHODIMP CGrabInputPin::EndOfStream(void) {
// Called when we are seeked
STDMETHODIMP CGrabInputPin::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {
return m_pDumpFilter->NewSegment(tStart, tStop, dRate);
}
}
3 changes: 1 addition & 2 deletions Source/Video/GrabFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class CGrab

class CGrabFilter : public CBaseFilter
{

CCritSec m_ReceiveLock;
bool m_doGrab;
CGrabCallback* m_callback;
Expand Down Expand Up @@ -81,4 +80,4 @@ class CGrabInputPin : public CRenderedInputPin
STDMETHODIMP NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) override;
};

#endif
#endif

0 comments on commit 2a81014

Please sign in to comment.