WMF: fix memory leaks.

Release requested interfaces.

Task-number: QTBUG-32481
Change-Id: I846981f6a7a7ea77588b9322fc41e05e583bdb15
Reviewed-by: Wouter Huysentruit <wouter_huysentruit@hotmail.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Reviewed-by: Jeff Tranter <jtranter@ics.com>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
This commit is contained in:
Nodir Temirkhodjaev
2014-09-05 16:29:41 +05:00
parent 4c5aec9bb6
commit 5be2524328
2 changed files with 32 additions and 27 deletions

View File

@@ -244,7 +244,6 @@ void MFAudioDecoderControl::handleMediaSourceReady()
} }
if (m_sourceResolver->mediaSource()) { if (m_sourceResolver->mediaSource()) {
IMFPresentationDescriptor *pd = 0;
if (mediaType && m_resampler) { if (mediaType && m_resampler) {
HRESULT hr = S_OK; HRESULT hr = S_OK;
hr = m_resampler->SetInputType(m_mfInputStreamID, mediaType, 0); hr = m_resampler->SetInputType(m_mfInputStreamID, mediaType, 0);
@@ -254,9 +253,11 @@ void MFAudioDecoderControl::handleMediaSourceReady()
qWarning() << "MFAudioDecoderControl: failed to SetInputType of resampler" << hr; qWarning() << "MFAudioDecoderControl: failed to SetInputType of resampler" << hr;
} }
} }
IMFPresentationDescriptor *pd;
if (SUCCEEDED(m_sourceResolver->mediaSource()->CreatePresentationDescriptor(&pd))) { if (SUCCEEDED(m_sourceResolver->mediaSource()->CreatePresentationDescriptor(&pd))) {
UINT64 duration = 0; UINT64 duration = 0;
pd->GetUINT64(MF_PD_DURATION, &duration); pd->GetUINT64(MF_PD_DURATION, &duration);
pd->Release();
duration /= 10000; duration /= 10000;
if (m_duration != qint64(duration)) { if (m_duration != qint64(duration)) {
m_duration = qint64(duration); m_duration = qint64(duration);

View File

@@ -266,6 +266,7 @@ void MFPlayerSession::handleMediaSourceReady()
//convert from 100 nanosecond to milisecond //convert from 100 nanosecond to milisecond
emit durationUpdate(qint64(m_duration / 10000)); emit durationUpdate(qint64(m_duration / 10000));
setupPlaybackTopology(mediaSource, sourcePD); setupPlaybackTopology(mediaSource, sourcePD);
sourcePD->Release();
} else { } else {
changeStatus(QMediaPlayer::InvalidMedia); changeStatus(QMediaPlayer::InvalidMedia);
emit error(QMediaPlayer::ResourceError, tr("Cannot create presentation descriptor."), true); emit error(QMediaPlayer::ResourceError, tr("Cannot create presentation descriptor."), true);
@@ -423,12 +424,15 @@ IMFTopologyNode* MFPlayerSession::addOutputNode(IMFStreamDescriptor *streamDesc,
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
hr = node->SetUINT32(MF_TOPONODE_STREAMID, sinkID); hr = node->SetUINT32(MF_TOPONODE_STREAMID, sinkID);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
if (SUCCEEDED(topology->AddNode(node))) if (SUCCEEDED(topology->AddNode(node))) {
handler->Release();
return node; return node;
}
} }
} }
} }
} }
handler->Release();
} }
node->Release(); node->Release();
return NULL; return NULL;
@@ -617,42 +621,39 @@ HRESULT BindOutputNode(IMFTopologyNode *pNode)
// Sets the IMFStreamSink pointers on all of the output nodes in a topology. // Sets the IMFStreamSink pointers on all of the output nodes in a topology.
HRESULT BindOutputNodes(IMFTopology *pTopology) HRESULT BindOutputNodes(IMFTopology *pTopology)
{ {
DWORD cNodes = 0; IMFCollection *collection;
IMFCollection *collection = NULL;
IUnknown *element = NULL;
IMFTopologyNode *node = NULL;
// Get the collection of output nodes. // Get the collection of output nodes.
HRESULT hr = pTopology->GetOutputNodeCollection(&collection); HRESULT hr = pTopology->GetOutputNodeCollection(&collection);
// Enumerate all of the nodes in the collection. // Enumerate all of the nodes in the collection.
if (SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
DWORD cNodes;
hr = collection->GetElementCount(&cNodes); hr = collection->GetElementCount(&cNodes);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
for (DWORD i = 0; i < cNodes; i++) { for (DWORD i = 0; i < cNodes; i++) {
hr = collection->GetElement(i, &element); IUnknown *element;
if (FAILED(hr)) hr = collection->GetElement(i, &element);
break; if (FAILED(hr))
break;
hr = element->QueryInterface(IID_IMFTopologyNode, (void**)&node); IMFTopologyNode *node;
if (FAILED(hr)) hr = element->QueryInterface(IID_IMFTopologyNode, (void**)&node);
break; element->Release();
if (FAILED(hr))
break;
// Bind this node. // Bind this node.
hr = BindOutputNode(node); hr = BindOutputNode(node);
if (FAILED(hr)) node->Release();
break; if (FAILED(hr))
break;
}
} }
collection->Release();
} }
if (collection)
collection->Release();
if (element)
element->Release();
if (node)
node->Release();
return hr; return hr;
} }
@@ -1510,8 +1511,11 @@ HRESULT MFPlayerSession::Invoke(IMFAsyncResult *pResult)
} }
} }
if (!m_closing) if (!m_closing) {
emit sessionEvent(pEvent); emit sessionEvent(pEvent);
} else {
pEvent->Release();
}
return S_OK; return S_OK;
} }