[SOLVED] MemoryInputStream leaked object driving me crazy

Hello guys, I spent all day solving some leaks in my plugin and it was everything ok until now.

This seems to be the last one leak that I have and I dont know what else I can do to solve it.

I´m getting this leak detected when removing my plugin from the host.

Leaked objects detected: 1 instance(s) of class MemoryInputStream

and bellow is the code I´m using MemoryInputStream class:

void OBNetwork::requestZipKit()
    auto url = OBPathHelper::getZipUrl(_workingKit.name);
    MemoryBlock memoryBlock;
    if (url.readEntireBinaryStream(memoryBlock))
        MemoryInputStream memStream(memoryBlock, false);

        auto _zipFile = std::unique_ptr<ZipFile>(new ZipFile(&memStream, true));

        if (_callbackDownloadFinished)
            _callbackDownloadFinished(true, std::move(_zipFile));
        if (_callbackDownloadFinished)
            _callbackDownloadFinished(false, nullptr);

Thanks in advance.


It was a dumb mistake and solved not passing the ownership to the zipfile class in the second parameter:

auto _zipFile = std::unique_ptr(new ZipFile(&memStream,  false ));

Thanks cpr2323.

Not sure about the issue you are posing about, BUT, you have a major error in your code. You are passing in memStream (which is a local stack based object), as a pointer into the ZipFile class, which takes ownership of memStream (as indicated by the 2nd paramater passed into ZipFile). I am not sure what happens to zipfle when it is passed to the callback, but you can’t pass the pointer to a stack based object to something that will try and delete it.

Hey cpr2323 thank you so much for your prompt response.
You´re rigth! That solved the problem:

auto _zipFile = std::unique_ptr<ZipFile>(new ZipFile(&memStream, false));

I was pretty sure that I had already tried the false one. Maybe I need some rest!

Anyways thank you again.

By the way, instead of writing

auto _zipFile = std::unique_ptr<ZipFile>(new ZipFile(&memStream, false));

you can use std::make_unique like that:

auto _zipFile = std::make_unique<ZipFile>(&memStream, false);

This will safe you a bit of typing :wink:

1 Like