# \[SOLVED\] MemoryInputStream leaked object driving me crazy

**URL:** <https://forum.juce.com/t/solved-memoryinputstream-leaked-object-driving-me-crazy/41906>\
**Category:** Audio Plugins\
**Created:** [September 24, 2020, 9:52pm UTC](https://forum.juce.com/t/solved-memoryinputstream-leaked-object-driving-me-crazy/41906 "2020-09-24T21:52:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tatolevicz](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@tatolevicz](https://forum.juce.com/u/tatolevicz)\
**Post date:** [September 24, 2020, 9:52pm UTC](https://forum.juce.com/t/solved-memoryinputstream-leaked-object-driving-me-crazy/41906/1 "2020-09-24T21:52:09Z")

</div>

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));
    }
    else
    {
        if (_callbackDownloadFinished)
            _callbackDownloadFinished(false, nullptr);
    }
}

```

Thanks in advance.

[SOLVED]

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.

---

<div class="post-metadata">

**Author:** ![cpr2323](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/cpr2323/32/18682_2.png) [@cpr2323](https://forum.juce.com/u/cpr2323)\
**Post date:** [September 24, 2020, 10:20pm UTC](https://forum.juce.com/t/solved-memoryinputstream-leaked-object-driving-me-crazy/41906/2 "2020-09-24T22:20:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tatolevicz](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@tatolevicz](https://forum.juce.com/u/tatolevicz)\
**Post date:** [September 24, 2020, 10:28pm UTC](https://forum.juce.com/t/solved-memoryinputstream-leaked-object-driving-me-crazy/41906/3 "2020-09-24T22:28:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [September 25, 2020, 8:51am UTC](https://forum.juce.com/t/solved-memoryinputstream-leaked-object-driving-me-crazy/41906/4 "2020-09-25T08:51:21Z")

</div>

By the way, instead of writing

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

```

you can use `std::make_unique` like that:

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

```

This will safe you a bit of typing 😉
