std::queue always result in a memory leak.

757 views
Skip to first unread message

Pradeepa Senanayake

unread,
Feb 19, 2016, 1:05:18 AM2/19/16
to cpputest
Hello All,

I have used std::queue in one of the class and it resulted in a memory leak. 

If I just define an std::queue as a member variable then it results in memory leak.

If I define it inside a function it does not report any memory leak.

I think this must be a bug in the framework.

Thank you.

Pradeepa Senanayake

unread,
Feb 19, 2016, 1:13:41 AM2/19/16
to cpputest
This must be a bug, 

I switched off the memory leak detector using MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();

Then the failure vanished.

Bas Vodde

unread,
Feb 19, 2016, 2:23:59 AM2/19/16
to cppu...@googlegroups.com

Hi,

No it is not :)

Try creating one queue first in main.

Thanks,

Bas

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pradeepa Senanayake

unread,
Feb 19, 2016, 3:49:01 AM2/19/16
to cpputest
In my project if I defines queue within a function then it works correctly.

But if I define the queue in the class as a private variable it fails, saying memory leak.

I will check more. 

Thank s for the reply.

Bas Vodde

unread,
Feb 19, 2016, 4:12:56 AM2/19/16
to cppu...@googlegroups.com

Hi,

No real need to check it :)

The dequeue contains a static member (cache) and therefore you must create one in the main (to initialize the cache) and then it shouldn’t leak anymore.

It isn’t a bug in the framework, but you could call it a bug in the StdC++ lib implementation :)

Bas

Pradeepa Senanayake

unread,
Feb 20, 2016, 4:26:52 AM2/20/16
to cpputest
So here is what I did.

I defined std::queue<int> test; in my main function in AllTersts.cpp.

But still I get the memory leaks.

Am I doing something wrong :S.

On Friday, February 19, 2016 at 12:53:59 PM UTC+5:30, Bas Vodde wrote:

Bas Vodde

unread,
Feb 21, 2016, 2:09:43 AM2/21/16
to cppu...@googlegroups.com

Hi,

Push some items on the queue to trigger the cache to be created :)

Bas

Pradeepa Senanayake

unread,
Feb 24, 2016, 12:53:55 AM2/24/16
to cpputest
Hello Bas,

Still it did not solve the issue.

I commented all the tests from the project. Then just created a dummy test which does nothing. 

Now the only part running is the Setup() which created an object of my class and Teardown() which deletes it.

When I run this, still I get a memory leak.

Then I pushed some data to the queue within the constructor.

Then I could see that CppUtest is reporting that data as leaked data. 

When I have time, I will create a dummy project and try the queue and see.

Look into this when time permits.

Bas Vodde

unread,
Feb 26, 2016, 6:10:37 PM2/26/16
to cppu...@googlegroups.com

Hi,

Can you send some code and tell me your platform?

Thanks!

Bas
Reply all
Reply to author
Forward
0 new messages