stevenrennermpls / lavfilters

Automatically exported from code.google.com/p/lavfilters
GNU General Public License v2.0
0 stars 0 forks source link

Resource leak in VideoDecoder when used via LoadLibrary #543

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When video decoder created in "reg free" way it does not free all resources.

Steps.
1. Extract all files from LAVFilters-0.65-x86.zip to some folder.
2. In application create graph, then create LAV Video Decoder filter using this 
function:

//  Creates COM object from DLL without registration in system
HRESULT CreateObjectFromPath(char* pPath, REFCLSID clsid, IUnknown** ppUnk, 
IUnknown** ppUnkFactory)
{
    if (!pPath || !ppUnk)
    {
        return E_INVALIDARG;
    }
    // load the target DLL directly
    HMODULE lib = LoadLibrary(pPath);
    if (!lib)
    {
        return HRESULT_FROM_WIN32(GetLastError());
    }

    // the entry point is an exported function
    FN_DLLGETCLASSOBJECT fn = (FN_DLLGETCLASSOBJECT)GetProcAddress(lib, "DllGetClassObject");
    if (fn == NULL)
    {
        return HRESULT_FROM_WIN32(GetLastError());
    }

    // create a class factory
    IClassFactoryPtr pCF;
    HRESULT hr = fn(clsid,  IID_IClassFactory,  (void**)&pCF);
    if (pCF == NULL)
    {
        hr = E_NOINTERFACE;
    }
    else
    {
        // ask the class factory to create the object
        hr = pCF->CreateInstance(NULL, IID_IUnknown, (void**)ppUnk);
        if (ppUnkFactory)
        {
            IUnknownPtr pUnk = pCF;
            *ppUnkFactory = pUnk.Detach();
        }
    }

    return hr;
}
//---------------------------------------------------------------------------
3. Add LAV Video Decoder to graph
4. Build whole playback graph
5. Run graph, stop and destroy it.

Here we still have extra running threads from LAVVideo.ax
When my application repeats steps 1-5 this leads to memory and handles 
leaks(threads count rises constantly, thus stack memory too).

I use many different filters in this way and all they works fine.
Even LAV Audio Decoder and LAV Splitter too.
I know this way is not documented way to use DirectShow filters but I like this 
way to avoid COM DLL hell. But unfortunately it fails with LAVVideo.ax

I do not know the cause, please if it is possible check it...

Original issue reported on code.google.com by dav...@davisr.com on 1 Jul 2015 at 11:38

GoogleCodeExporter commented 9 years ago
P.S. If use in normal way - all fine.

Original comment by dav...@davisr.com on 1 Jul 2015 at 11:39

GoogleCodeExporter commented 9 years ago
Are you sure you're properly releasing all the objects you created? Both the 
instance and the class factory?

Can you provide a small sample app that I can test to see which resources 
exactly may be hanging around? Source preferred, but binary would be fine.

Original comment by h.lepp...@gmail.com on 1 Jul 2015 at 3:05

GoogleCodeExporter commented 9 years ago
Sure I releasing class factory right here in this function - IClassFactoryPtr 
is smart ptr.
While this function is able to return refernece on class factory currently I do 
not use this ability.
All objects released too, via smart ptrs.

I'l create very small app for tests.

Original comment by dav...@davisr.com on 1 Jul 2015 at 3:09

GoogleCodeExporter commented 9 years ago
I'm so sorry...
During creation of test application I suddenly found bug in my code, result - 
not released interface, even using these smart ptrs.
Test application with wixed bug works fine, then I checked my main application 
with bug fixed - it works fine too.

So sorry again, and thank you very much for your job!

Original comment by dav...@davisr.com on 2 Jul 2015 at 9:39

GoogleCodeExporter commented 9 years ago
No problem, glad you solved it!

Original comment by h.lepp...@gmail.com on 2 Jul 2015 at 11:54